- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem013.cpp
More file actions
Latest commit
30 lines (27 loc) · 683 Bytes
/
Copy pathproblem013.cpp
File metadata and controls
30 lines (27 loc) · 683 Bytes
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
// Compile with the following command:
// g++ problem013.cpp -lgmpxx -lgmp
#include<gmpxx.h>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<string>
intmain(int argc, char* argv[])
{
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " <input>\n";
return0;
}
std::ifstream file(argv[1]);
if (!file.is_open()) {
std::cerr << "Cannot open " << argv[1] << '\n';
returnEXIT_FAILURE;
}
mpz_class sum;
std::string line;
while (std::getline(file, line)) {
sum += mpz_class(line);
}
std::string ans(sum.get_str(), 0, 10);
std::cout << "Answer: " << ans << '\n';
return0;
}