-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc015.cpp
45 lines (41 loc) · 828 Bytes
/
c015.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
#include <iostream>
#include <ios>
#include <cstdio>
#include <cstring>
long long int revNum(long long int);
inline bool isParlindrome(long long int);
int main()
{
//std::cout << revNum(1234);
std::ios_base::sync_with_stdio(false);
int N;
std::cin >> N;
for(int i=0; i!=N; ++i){
long long a;
std::cin >> a;
int round = 1;
a += revNum(a);
while(!isParlindrome(a)){
//std::cout << a;
a += revNum(a);
round += 1;
}
std::cout << round << " " << a << "\n";
}
return 0;
}
long long int revNum(long long int a)
{
char buf[22];
sprintf(buf, "%lld", a);
//std::cout << buf;
int length = strlen(buf);
long long int result = 0;
for(int i = length-1; i>=0; --i)
result = result * 10 + static_cast<int>(buf[i] - '0');
return result;
}
bool isParlindrome(long long int a)
{
return a == revNum(a);
}