-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday03.cpp
More file actions
44 lines (40 loc) 路 1.18 KB
/
Copy pathday03.cpp
File metadata and controls
44 lines (40 loc) 路 1.18 KB
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 <fstream>
#include <string>
int main() {
long count = 0;
std::ifstream file("input.txt");
std::string str;
while (std::getline(file, str))
{
std::string strCheck = str;
int first = 0;
int second = 0;
for (int i = 9; i >= 0; i--) {
while (str.find(std::to_string(i)) != std::string::npos) {
std::size_t pos = str.find(std::to_string(i));
if (first == 0 && pos != std::string::npos) {
if (pos == 99) {
second = i;
i--;
continue;
}
first = i;
str.erase(str.begin(), str.begin()+pos+1);
} else if (second == 0 && pos != std::string::npos) {
second = i;
break;
}
if (first != 0 && second != 0) {
break;
}
}
if (first != 0 && second != 0) {
break;
}
}
count = count + first*10 + second;
}
std::cout << count << std::endl;
return 0;
}