-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02.cpp
More file actions
31 lines (26 loc) · 846 Bytes
/
Copy pathday02.cpp
File metadata and controls
31 lines (26 loc) · 846 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
int main() {
long count = 0;
std::ifstream file("input.txt");
std::string str1;
while (std::getline(file, str1, ','))
{
std::string delimiter = "-";
std::string str0 = str1.substr(0, str1.find(delimiter));
str1.erase(0, str1.find(delimiter) + delimiter.length());
long lower = stol(str0);
long upper = stol(str1);
while (lower <= upper) {
std::string half = std::to_string(lower).substr(0, std::to_string(lower).length()/2);
std::string otherHalf = std::to_string(lower).substr(std::to_string(lower).length()/2);
if (half == otherHalf) {
count = count + lower;
}
lower++;
}
}
std::cout << count << std::endl;
return 0;
}