-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbesum.cpp
More file actions
39 lines (33 loc) · 780 Bytes
/
Copy pathbesum.cpp
File metadata and controls
39 lines (33 loc) · 780 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
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
void besum(istream& file)
{
long long sum = 0;
char * buffer = new char [4];
while (!file.eof()) {
file.read(buffer, 4);
if (file.eof()) {
break;
}
unsigned int number = 0;
for (int i = 0; i < 4; ++i) {
number += (unsigned int)buffer[i] * (1 << (i * 8));
}
sum += number;
}
cout << sum << endl;
}
int main(int argc, char *argv[]) {
for (size_t i = 1; i < (size_t) argc; ++i) {
string filename(argv[i]);
if (filename == "-") {
besum(cin);
} else {
ifstream file(filename);
besum(file);
}
}
}