You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.1 KiB
C++
61 lines
1.1 KiB
C++
2 years ago
|
#include <algorithm>
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
|
#include <tuple>
|
||
|
#include <vector>
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
std::vector<std::pair<char, int>> steps;
|
||
|
|
||
|
while (1) {
|
||
|
std::string line;
|
||
|
std::getline(std::cin, line);
|
||
|
if (std::cin.eof())
|
||
|
break;
|
||
|
|
||
|
int n = line.size() < 6 ? 0 : stoi(line.substr(5));
|
||
|
steps.emplace_back(line.front(), n);
|
||
|
}
|
||
|
|
||
|
int cx = 0;
|
||
|
|
||
|
int cycle = 1;
|
||
|
int adding = 0;
|
||
|
int X = 1;
|
||
|
int strength = 0;
|
||
|
for (int i = 0; i < steps.size();) {
|
||
|
const auto& [ins, n] = steps[i];
|
||
|
|
||
|
if (abs(X - cx) < 2)
|
||
|
std::cout << '#';
|
||
|
else
|
||
|
std::cout << '.';
|
||
|
|
||
|
if (++cx == 40) {
|
||
|
std::cout << std::endl;
|
||
|
cx = 0;
|
||
|
}
|
||
|
|
||
|
++cycle;
|
||
|
|
||
|
if (adding != 0) {
|
||
|
X += adding;
|
||
|
adding = 0;
|
||
|
++i;
|
||
|
} else if (ins == 'a') {
|
||
|
adding = n;
|
||
|
} else if (ins == 'n') {
|
||
|
++i;
|
||
|
}
|
||
|
|
||
|
if ((cycle - 20) % 40 == 0)
|
||
|
strength += cycle * X;
|
||
|
}
|
||
|
|
||
|
std::cout << "strength: " << strength << std::endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|