42 lines
911 B
C++
42 lines
911 B
C++
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
#include <algorithm>
|
||
|
|
||
|
|
||
|
int main(int argc, char *argv[]) {
|
||
|
if(argc != 2) {
|
||
|
std::cerr << "Usage " << argv[0] << " <input>" << std::endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
std::ifstream file;
|
||
|
file.open(argv[1]);
|
||
|
|
||
|
std::string line;
|
||
|
std::vector<int> groups;
|
||
|
int sum = 0;
|
||
|
while(file) {
|
||
|
std::getline(file, line);
|
||
|
std::cout << "got " << line << std::endl;
|
||
|
|
||
|
if(line == "") {
|
||
|
if(sum > 0)
|
||
|
groups.push_back(sum);
|
||
|
sum = 0;
|
||
|
} else {
|
||
|
sum += std::stoi(line);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for(int sum : groups) {
|
||
|
std::cout << "sum " << sum << std::endl;
|
||
|
}
|
||
|
std::cout << "Parsed " << groups.size() << " groups" << std::endl;
|
||
|
|
||
|
std::cout << "Max is " << *std::max_element(groups.begin(), groups.end()) << std::endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|