-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10018.cpp
More file actions
55 lines (46 loc) · 715 Bytes
/
10018.cpp
File metadata and controls
55 lines (46 loc) · 715 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
51
52
53
54
55
#include<stdio.h>
/* Reverse and Add - 10018 */
long long inverte(long long n){
long long i,j,aux1,aux2,ant,num[11];
i=0;
aux1=10;
aux2=1;
ant=0;
while(n/aux2>0)
{
num[i]=(n%aux1-ant)/aux2;
ant=n%aux1;
aux1*=10;
aux2*=10;
i++;
}
aux1=1;
n=0;
for(j=i-1;j>=0;j--)
{
n+=aux1*num[j];
aux1*=10;
}
return n;
}
main(){
/* para funcionar no windows troca o long long por um int64*/
long long i,j,c,ciclo,n1,n2,palidrome;
scanf("%lld",&c);
for(i=1;i<=c;i++)
{
palidrome=0;
ciclo=0;
scanf("%lld",&n1);
while(!palidrome)
{
n2=inverte(n1);
n1=n1+n2;
n2=inverte(n1);
ciclo++;
if(n1==n2)
palidrome=1;
}
printf("%lld %lld\n",ciclo,n2);
}
}