-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_02_2.cc
40 lines (34 loc) · 855 Bytes
/
puzzle_02_2.cc
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
#include <iostream>
#include <sstream>
#include <limits>
#include <vector>
int main() {
std::string line;
size_t checksum = 0;
while(std::getline(std::cin, line)) {
if (line.empty()) {
break;
}
std::vector<int> nums;
std::stringstream ss{line};
while(!ss.eof()) {
size_t x;
ss >> x;
nums.push_back(x);
}
for (int i = 0; i < nums.size(); ++i) {
int a = nums[i];
for (int j = 0; j < nums.size(); ++j) {
if (i == j) {
continue;
}
int b = nums[j];
int x = a/b;
if (a == x*b) {
checksum += x;
}
}
}
}
std::cout << "checksum: " << checksum << "\n";
}