• 博客访问： 989266
• 博文数量： 153
• 博客积分： 4195
• 博客等级： 上校
• 技术积分： 2631
• 用 户 组： 普通用户
• 注册时间： 2009-06-22 11:32

2012年（7）

2010年（35）

2009年（111）

2009-11-16 11:28:15

#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;
}

chinaunix网友2009-11-17 12:19:28