NYOJ6174问题

来源:互联网 发布:随机滚动抽奖软件 编辑:程序博客网 时间:2024/06/01 07:13
#include <stdio.h>
int main (){
int a,b[4],c,d,e,f,t;
scanf("%d",&f);
while (f>0){
d=1;
scanf ("%d",&a);
b[3]=a%10;
b[2]=a/10%10;
b[1]=a/100%10;
b[0]=a/1000;
for (c=4;c>0;c--){
for (e=2;e>=0;e--){
if (b[e]<b[e+1]){
t=b[e];
b[e]=b[e+1];
b[e+1]=t;
}
}
}
a=b[0]*1000+b[1]*100+b[2]*10+b[3];
while (a!=6174){
a=b[0]*1000+b[1]*100+b[2]*10+b[3];
a=a-(b[3]*1000+b[2]*100+b[1]*10+b[0]);
b[3]=a%10;
b[2]=a/10%10;
b[1]=a/100%10;
b[0]=a/1000;
for (c=4;c>0;c--){
for (e=2;e>=0;e--){
if (b[e]<b[e+1]){
t=b[e];
b[e]=b[e+1];
b[e+1]=t;
}
}
}
d++;
}
printf("%d\n",d);
f--;
}
return 0;
0 0