-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.1.cpp
44 lines (41 loc) · 838 Bytes
/
8.1.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
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <cstdint>
std::size_t parseStringSize(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 += parseStringSize(line);
}
std::cout << file_size - string_size;
}
std::size_t parseStringSize(const std::string& line)
{
std::string builder;
for (std::size_t i = 1; i < line.size() - 1; i++)
{
if (line[i] == '\\' && line[i + 1] == 'x')
{
builder += "_";
i += 3;
}
else if (line[i] == '\\')
{
builder += "_";
i++;
}
else
builder += line[i];
}
return builder.size();
}