-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01.cpp
More file actions
35 lines (30 loc) 路 711 Bytes
/
Copy pathday01.cpp
File metadata and controls
35 lines (30 loc) 路 711 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
32
33
34
35
#include <iostream>
#include <fstream>
#include <string>
int main() {
int dial = 50;
int count = 0;
std::ifstream file("input.txt");
std::string str;
while (std::getline(file, str))
{
if (str.find("L") != std::string::npos) {
str.erase(0,1);
dial = dial - stoi(str);
} else if (str.find("R") != std::string::npos) {
str.erase(0,1);
dial = dial + stoi(str);
}
while (dial < 0) {
dial = dial + 100;
}
while (dial > 99) {
dial = dial - 100;
}
if (dial == 0) {
count++;
}
}
std::cout << count << std::endl;
return 0;
}