写写代码真不错,把c语言的要点又感觉温习了一遍。
#include
struct bigandsmall
{
int big;
int small;
};
int biggertosmaller(int num,struct bigandsmall *this)
{
int a[4] ;
int i,j,tmp;
if(num == 999)
{
this->big = 999;
this->small = 999;
return 0;
}
a[0] = num/1000;
a[1] = num%1000/100;
a[2] = num%100/10;
a[3] = num%10;
for(i = 0; i < 4; i++)
for(j = i+1; j < 4; j++)
{
if(a[i] <= a[j])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
this->big = a[0]*1000+a[1]*100+a[2]*10+a[3];
this->small = a[3]*1000+a[2]*100+a[1]*10+a[0];
// printf("%d%d%d%d\n",a[0],a[1],a[2],a[3]);
return 0;
}
int main()
{
int num,bigger,smaller,result,count;
struct bigandsmall this;
while(scanf("%d",&num),num!=-1)
{
count = 0;
if(num < 1000 || num > 9999 || num %1111 == 0)
{
printf("NO!!\n");
continue;
}
printf("N=%d\n",num);
do
{
if(count)
num = bigger-smaller;
count++;
biggertosmaller(num,&this);
bigger = this.big;
smaller = this.small;
result = bigger-smaller;
printf("%d - %d = %d\n",bigger,smaller,result);
}
while(result != 6174 && result != 0);
printf("OK!! %d timers\n",count);
}
return 0;
}
阅读(1189) | 评论(1) | 转发(0) |