1
0
Fork 0
Advent2022/Day10/part2.cpp

50 lines
958 B
C++

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string line;
int cycle = 1;
int x = 0;
int accumulator = 1;
while(getline(cin, line))
{
if (accumulator >= x-1 && accumulator <= x+1)
{
cout << "#";
}
else
{
cout << " ";
}
cycle++;
x++;
if (0 == x%40)
{
x = 0;
cout << endl;
}
if (line.substr(0,4).compare("addx") == 0)
{
if (accumulator >= x-1 && accumulator <= x+1)
{
cout << "#";
}
else
{
cout << " ";
}
accumulator += stoi(line.substr(5));
cycle++;
x++;
if (0 == x%40)
{
x = 0;
cout << endl;
}
}
}
}