-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.2.cpp
50 lines (47 loc) · 1014 Bytes
/
8.2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <cstdint>
std::size_t builtStringSize(const std::string &);
int main()
{
std::ifstream fin("test.txt");
std::string line;
long long file_size = 0, string_size = 0;
while (std::getline(fin, line))
{
file_size += line.size();
string_size += builtStringSize(line);
}
std::cout << string_size - file_size;
}
std::size_t builtStringSize(const std::string& line)
{
std::string builder;
builder += "\"\\\"";
for (std::size_t i = 1; i < line.size(); i++)
{
if (line[i] == '\"')
builder += "\\\"";
else if (line[i] == '\\' && line[i + 1] == '\"')
{
builder += "\\\\\\\"";
i++;
continue;
}
else if (line[i] == '\\' && line[i + 1] == '\\')
{
builder += "\\\\\\\\";
i++;
continue;
}
else if (line[i] == '\\')
builder += "\\";
builder += line[i];
}
return builder.size();
}