Day 10
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
string line;
|
||||
int cycle = 1;
|
||||
int accumulator = 1;
|
||||
int answer = 0;
|
||||
while(getline(cin, line))
|
||||
{
|
||||
int next_adden = 0;
|
||||
if (line.substr(0,4).compare("addx") == 0)
|
||||
{
|
||||
next_adden = stoi(line.substr(5));
|
||||
cycle++;
|
||||
if ((cycle-20)%40 == 0)
|
||||
{
|
||||
answer += cycle*accumulator;
|
||||
}
|
||||
accumulator += next_adden;
|
||||
}
|
||||
|
||||
cycle++;
|
||||
if ((cycle-20)%40 == 0)
|
||||
{
|
||||
answer += cycle*accumulator;
|
||||
}
|
||||
}
|
||||
cout << answer << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user