Branch data Line data Source code
1 : : #include <iostream>
2 : : #include <fstream>
3 : : #include <string>
4 : : #include <array>
5 : : using namespace std;
6 : :
7 : 2 : int main() {
8 : 2 : constexpr int width = 101;
9 : 2 : constexpr int height = 103;
10 : :
11 : 2 : ifstream inputFile("input.txt");
12 : :
13 [ + + ]: 2 : if (!inputFile) {
14 : 1 : cerr << "Error: Could not open input.txt" << endl;
15 : 1 : return 1;
16 : : }
17 : 1 : array<int, 4> quadrants{};
18 : : int px;
19 : : int py;
20 : : int vx;
21 : : int vy;
22 [ + + ]: 501 : for (string line; getline(inputFile, line); ) {
23 : 500 : sscanf(line.c_str(), "p=%d,%d v=%d,%d", &px, &py, &vx, &vy);
24 : :
25 : 500 : px = (px + 100 * vx % width + width) % width;
26 : 500 : py = (py + 100 * vy % height + height) % height;
27 [ + + + + ]: 500 : if (px != width / 2 && py != height / 2) {
28 [ + + ]: 495 : ++quadrants[static_cast<int>(px > width / 2) + 2 * static_cast<int>(py > height / 2)];
29 : : }
30 : 1 : }
31 : :
32 : 1 : cout << quadrants[0] * quadrants[1] * quadrants[2] * quadrants[3] << endl;
33 [ + + ]: 3 : }
|