-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj1503.cpp
86 lines (72 loc) · 1.65 KB
/
poj1503.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Problem: 1503, Integer Inquiry
* User: LoiteringLeo
* Memory: 756k Time: 0MS
* Language: G++ Result: Accepted
*/
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define MAX_CHAR 100
#define MAX_LINE 100
int main()
{
string s;
vector<char> cvec[MAX_LINE];
vector<char>::iterator citer[MAX_LINE];
int line = 0;
int max_len = 0;
int i = 0;
while (getline(cin, s) && s != "0") {
if (max_len < s.length()) {
max_len = s.length();
}
for (i = s.length() - 1; i >= 0; i--) {
cvec[line].push_back(s.at(i));
}
for (i = s.length(); i < max_len; i++) {
cvec[line].push_back('0');
}
line++;
s.clear();
}
#if 0
for (i = 0; i < line; i++) {
for (vector<char>::reverse_iterator ri = cvec[i].rbegin();
ri != cvec[i].rend(); ri++) {
cout << *ri;
}
cout << endl;
}
#endif
for (i = 0; i < line; i++) {
citer[i] = cvec[i].begin();
}
int sum;
int carry = 0;
int j;
vector<int> retv;
for (j = 0; j < max_len; j++) {
sum = 0;
for (i = 0; i < line; i++) {
sum += *(citer[i]) - '0';
(citer[i])++;
}
sum += carry;
carry = sum / 10;
sum = sum % 10;
retv.push_back(sum);
}
while (carry > 0) {
sum = carry % 10;
retv.push_back(sum);
carry /= 10;
}
for (vector<int>::reverse_iterator riter = retv.rbegin();
riter != retv.rend(); riter++) {
cout << *riter;
}
cout << endl;
return 0;
}