-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.cpp
More file actions
41 lines (30 loc) · 677 Bytes
/
Copy pathsum.cpp
File metadata and controls
41 lines (30 loc) · 677 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
39
#include<iostream>
#include<cstring>
using namespace std;
int str2int(string str) {
int result = 0;
for(int i = 0; i < str.length(); i++) {
short int v = str[i] - '0';
if (v < 0 || v > 9) {
throw "Invalid char at number ";
}
result = result * 10 + v;
}
return result;
}
int main() {
string v;
int sum = 0;
while (cin.peek() != '\n') {
cin >> v;
try {
int inumber = str2int(v);
sum += inumber;
}
catch(const char* msg) {
cout << msg << v << endl;
}
}
cout << "Suma este " << sum << endl;
return 0;
}