-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10018.cpp
61 lines (50 loc) · 1.31 KB
/
10018.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
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int iter, tmp_iter, arr_1[21], arr_2[21], index, *pre, *curr, *tmp, carry;
long base;
bool flag;
curr = arr_1;
pre = arr_2;
cin >> iter;
while (iter-- > 0) {
cin >> base;
index = 0;
while (base > 0) {
pre[index++] = (int)(base % 10);
base /= 10;
}
tmp_iter = 0;
while (true) {
flag = true;
for (int i = 0; i < index / 2; ++i)
if (pre[i] != pre[index - i - 1]) {
flag = false;
break;
}
if (flag) break;
tmp_iter++;
carry = 0;
for (int j = 0; j < index; ++j) {
curr[j] = pre[j] + pre[index - j - 1] + carry;
if (curr[j] >= 10) {
curr[j] -= 10;
carry = 1;
}
else
carry = 0;
}
if (carry > 0) curr[index++] = 1;
tmp = curr;
curr = pre;
pre = tmp;
}
cout << tmp_iter << " ";
for (int i = 0; i < index; ++i)
cout << pre[i];
cout << endl;
}
return 0;
}