-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1221.cpp
More file actions
50 lines (35 loc) · 774 Bytes
/
Copy path1221.cpp
File metadata and controls
50 lines (35 loc) · 774 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
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
bool isP(ll n) {
string str = to_string(n);
for ( int i = 0; i <= str.length() - 1; ++ i ) {
if ( str[i] != str[str.length() - 1 - i] ) {
return false;
}
}
return true;
}
int solve(ll n ) {
int cnt = 0;
while ( ! isP(n) ) {
string str = to_string(n);
string res(str.rbegin(), str.rend());
ll num = stoll(res);
n += num;
cnt ++;
if ( cnt > 8 ) return 0;
}
return cnt;
}
int main() {
int t;
cin >> t;
while ( t -- ) {
ll n;
cin >> n;
cout << solve(n) << endl;
}
return 0;
}