2018/Day08/Day8A.cpp

37 lines
669 B
C++
Raw Normal View History

2018-12-08 22:31:29 +00:00
#include <iostream>
#include <vector>
std::vector<int> read_input()
{
std::vector<int> input;
input.reserve(20000);
int i = 0;
2018-12-08 22:34:14 +00:00
while (std::cin >> i)
2018-12-08 22:31:29 +00:00
input.push_back(i);
return input;
}
int read_node(std::vector<int>::iterator &it)
{
int child_count = *it++;
int meta_count = *it++;
int value = 0;
2018-12-08 22:34:14 +00:00
for (int i = 0; i < child_count; i++)
2018-12-08 22:31:29 +00:00
value += read_node(it);
2018-12-08 22:34:14 +00:00
for (int i = 0; i < meta_count; i++)
2018-12-08 22:31:29 +00:00
value += *it++;
return value;
}
int main(int argc, char **argv)
{
std::vector<int> input = read_input();
auto iterator = input.begin();
std::cout << read_node(iterator) << std::endl;
}