-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1a.cpp
More file actions
94 lines (85 loc) · 1.46 KB
/
Copy pathday1a.cpp
File metadata and controls
94 lines (85 loc) · 1.46 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <cassert>
namespace day1a
{
int main()
{
// std::string input0 = R"(L68
//L30
//R48
//L5
//R60
//L55
//L1
//L99
//R14
//L82)";
std::string input0;
std::ifstream ifile("input1a.txt");
if (ifile.is_open())
{
while (!ifile.eof())
{
std::string line;
std::getline(ifile, line);
input0 += line + '\n';
}
input0.pop_back(); // no trailing newline character please
//__debugbreak();
}
else
{
assert(0);
}
std::vector<std::string> input0a;
std::string temp;
for (char c : input0)
{
if (c == '\n')
{
input0a.push_back(temp);
temp = "";
continue;
}
temp += c;
}
input0a.push_back(temp);
std::vector<std::string> input0b;
std::istringstream iss(input0);
for (std::string line; std::getline(iss, line);)
{
input0b.push_back(line);
}
std::vector<std::pair<char, int>> input1a;
for (auto& s : input0a)
{
char dir = s[0];
int cnt = std::stoi(s.substr(1));
input1a.emplace_back(dir, cnt);
}
int dial = 50;
int count = 0;
for (auto& c : input1a)
{
if (c.first == 'L')
{
dial -= c.second;
}
else
{
dial += c.second;
}
while (dial >= 100)
dial -= 100;
while (dial < 0)
dial += 100;
if (dial == 0)
count++;
}
__debugbreak();
return 0;
}
}