-
Notifications
You must be signed in to change notification settings - Fork 14
/
10018.cpp
49 lines (39 loc) · 1.2 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
#include<iostream>
using namespace std;
long reverse(long n);
int main()
{
long num=0,rev_num=0;
int i=0,n=0,iter=0;
cin>>n;
for(i=0;i<n;i++)
{
num=0;rev_num=0;iter=0;
cin>>num;
rev_num=reverse(num);
if(num==rev_num)
cout<<"0 "<<num<<endl;
else
{
while(num!=rev_num)
{
iter++;
num=num+rev_num;
rev_num=reverse(num);
}
cout<<iter<<" "<<num<<endl;
}
}
return 0;
}
long reverse(long n)
{
long rev_n=0;
while(n)
{
rev_n*=10;
rev_n+=n%10;
n/=10;
}
return rev_n;
}