标签:排列 text scan fonts ios printf return size alt
例子输出:
4
代码例如以下(1):
#include <iostream>
using namespace std;
int main()
{
int i,j,t,k,n,b,s;
int a[4];
cin>>s;
while(s--)
{
cin>>b;
int count=1;
while(b!=6174)
{
a[0]=(b)%10;
a[1]=(b)/10%10;
a[2]=(b)/100%10;
a[3]=(b)/1000;
for(j=0;j<3;j++) //j轮比較
for(i=0;i<3-j;i++) //3-j次两两比較
if(a[i]>a[i+1]) //从小到大排列
{
t=a[i];a[i]=a[i+1];a[i+1]=t;
}
k=a[0]*1000+a[1]*100+a[2]*10+a[3]*1;
n=a[3]*1000+a[2]*100+a[1]*10+a[0]*1;
b=n-k;
//cout<<b<<endl;
count++;
}
cout<<count;
cout<<endl;
}
return 0;
}
代码例如以下(2)<pre name="code" class="cpp">#include<stdio.h>
int Test(int m)
{
int c[4],j,k,temp,a,b;
c[0]=(m)%10;
c[1]=(m)/10%10;
c[2]=(m)/100%10;
c[3]=(m)/1000;
for(j=0;j<3;++j)
for(k=j+1;k<4;++k)
{
if(c[j]<c[k]) //从大到小排序
{
temp=c[j];
c[j]=c[k];
c[k]=temp;
}
}
a=1000*c[0]+100*c[1]+10*c[2]+c[3];
b=1000*c[3]+100*c[2]+10*c[1]+c[0];
return a-b;
}
int main()
{
int n,m,count;
int c[4];
scanf("%d",&n);
while(n--)
{
count=1;
scanf("%d",&m);
while(m!=6174)
{
m=Test(m);
count++;
}
printf("%d\n",count);
}
return 0;
}标签:排列 text scan fonts ios printf return size alt
原文地址:http://www.cnblogs.com/zhchoutai/p/6830240.html