-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.cpp
More file actions
38 lines (35 loc) · 796 Bytes
/
day1.cpp
File metadata and controls
38 lines (35 loc) · 796 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
36
37
38
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
ifstream inputFile("input.txt");
if (!inputFile.is_open()) {
cerr << "Error opening file\n";
return 1;
}
string line;
int currentNumber = 50;
int count = 0;
while (getline(inputFile, line)) {
char dir = line[0];
int num = stoi(line.substr(1));
if (dir == 'R') {
currentNumber = currentNumber + num;
while (currentNumber > 99) {
currentNumber = currentNumber - 100;
count++;
}
}
if (dir == 'L') {
currentNumber = currentNumber - num;
while (currentNumber < 0) {
currentNumber = currentNumber + 100;
count++;
}
}
}
cout << "count: " << count << '\n';
inputFile.close();
return 0;
}