diff options
Diffstat (limited to 'day02.cc')
-rw-r--r-- | day02.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/day02.cc b/day02.cc new file mode 100644 index 0000000..ba955ee --- /dev/null +++ b/day02.cc @@ -0,0 +1,31 @@ +#include <algorithm> +#include <iostream> +#include <istream> +#include <iterator> +#include <sstream> +#include <vector> + +using namespace std; + +int main() +{ + string line; + int s1 = 0, s2 = 0; + + while (getline(cin, line)) { + istringstream is{line}; + vector<int> v{istream_iterator<int>(is), + istream_iterator<int>()}; // slurp it for part 2 + + auto [min, max] = minmax_element(begin(v), end(v)); + s1 += *max - *min; + + for (int a : v) + for (int b : v) + if (a > b && a % b == 0) + s2 += a / b; + } + + cout << s1 << endl << s2 << endl; + return 0; +} |