-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtyama_PG110502.c
61 lines (55 loc) · 976 Bytes
/
tyama_PG110502.c
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
//tyama070521reverse.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if 0
reverse()の設計ミス。place()もpower()も不必要でした。
int place(unsigned u){
unsigned t=u/10;
if(!t)return 0;
return (place(t))+1;
/*asmが使えれば絶対その方が早い。Cだと++がコンパイルエラーにw
__asm{
xor edx,edx
mov eax, u
div 10
test eax, 0
jz @return
push eax
call place
inc eax
ret
@return
xor eax, eax
ret
}
*/
}
//マイコンクラブのscheme講習会で作ったものの移植w
unsigned power(unsigned u, int i){
if(!i)return 1;
return u*power(u,--i);
}
#endif
unsigned reverse(unsigned u){
unsigned ret=0;
while(u){
ret=ret*10+u%10;
u/=10;
}
return ret;
}
void main(){
unsigned u;
int i,n,count;
scanf("%d", &n);
for(i=0;i<n;i++){
count=0;
scanf("%u", &u);
while(u!=reverse(u)){
u+=reverse(u);
count++;
}
printf("%d %u\n",count,u);
}
}