1 #include<stdio.h> 2 int main() 3 { 4 int a,b,c,d,n,i,j,k,t,sum,sum1; 5 int num[100],num1[100],num2[100],num3[100]; 6 scanf("%d",&n); 7 c=0; 8 for(i=0;i<n;i++) 9 scanf("%d",&num[i]); 10 for(i=0;i<n;i++) 11 { 12 a=num[i];d=1; 13 s1:b=0;sum=0;sum1=0; 14 while(a!=0)//取出个各位数; 15 { 16 num1[b++]=a%10; 17 a=a/10; 18 } 19 for(j=0;j<b-1;j++)//冒泡排序; 20 for(k=0;k<4-j-1;k++) 21 { 22 if(num1[k]<num1[k+1]) 23 {t=num1[k];num1[k]=num1[k+1];num1[k+1]=t;} 24 } 25 for(j=0;j<4;j++) 26 { 27 sum=sum*10+num1[j]; 28 } 29 for(j=0;j<b-1;j++)//冒泡; 30 for(k=0;k<4-j-1;k++) 31 { 32 if(num1[k]>num1[k+1]) 33 {t=num1[k];num1[k]=num1[k+1];num1[k+1]=t;} 34 } 35 for(j=0;j<4;j++) 36 { 37 sum1=sum1*10+num1[j]; 38 } 39 a=sum-sum1; 40 if(a!=6174)//循环判断次数; 41 { 42 d++;b=0;//sum=0;sum1=0; 43 goto s1; 44 } 45 num3[c++]=d; 46 } 47 for(i=0;i<c;i++) 48 printf("%d\n",num3[i]+1); 49 return 0; 50 } 转载于:https://www.cnblogs.com/soTired/p/4503543.html