-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path126AOC.cpp
More file actions
55 lines (44 loc) · 1.12 KB
/
Copy path126AOC.cpp
File metadata and controls
55 lines (44 loc) · 1.12 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
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
void shiftL(int number_rotated, int &lock)
{
int remaining = number_rotated % 100;
lock -= remaining;
if(lock < 0)
lock += 100;
}
void shiftR(int number_rotated, int &lock)
{
int remaining = number_rotated % 100;
lock = (lock + remaining) % 100;
}
int main()
{
// Read from file instead of cin
ifstream inputFile("input.txt");
if (!inputFile.is_open()) {
cerr << "Error: Cannot open input.txt\n";
return 1;
}
int lock = 50;
int zeros = 0;
string input;
while(getline(inputFile, input))
{
input.erase(std::remove(input.begin(), input.end(), ' '), input.end());
if (input.size() < 2)
continue;
int number_rotated = stoi(input.substr(1));
if(input[0] == 'L')
shiftL(number_rotated, lock);
else if(input[0] == 'R')
shiftR(number_rotated, lock);
if(lock == 0)
zeros++;
}
inputFile.close();
cout << zeros << "\n";
return 0;
}