| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
i know,过了In Reply To:WHY WA Posted by:350053879 at 2006-04-12 11:31:16 > #include<stdio.h>
> #include<string.h>
>
>
>
> int num;
> int power(int t,int k)
> {
> int sum=1;
> for(int i=1;i<=k;i++)
> sum*=t;
> return sum;
> }
> int Crabic(int n,int k)
> {
> int max=0,min=0;
> int a[4];
> int temp;
> int i,j;
> for(i=0;i<k;i++)
> {
> a[i]=n%10;
> n=n/10;
> }
> for(i=0;i<k;i++)
> for(j=i+1;j<k;j++)
> if(a[i]>a[j])
> {
> temp=a[i];
> a[i]=a[j];
> a[j]=temp;
> }
> num++;
> for(j=k-1;j>=0;j--)
> {
> max+=power(10,j)*a[j];
> min+=power(10,k-j-1)*a[j];
> }
> printf("%d-%d=%d\n",max,min,max-min);
> if(max-min==0||max-min==6174)
> {
> printf("Ok!! %d times\n",num);
> //exit(0);
> }
> temp=max-min;
> return temp;
> }
> int main()
> {
> int n;
> int a[4];
> while(scanf("%d",&n)!=EOF)
> {
> if(n==-1) break;
> int temp=n;
> for(int i=0;i<4;i++)
> {
> a[i]=temp%10;
> temp=temp/10;
> }
> num=0;
> printf("N=%d:\n",a[3]*1000+a[2]*100+a[1]*10+a[0]);
> if(n%1111==0||n>9999||n<1000)
> {
> printf("No!!\n");
> continue;
> }
> while(1)
> {
> if(n>=1000) n=Crabic(n,4);
> else if(n>=100) n=Crabic(n,3);
> else if(n>=10) n=Crabic(n,2);
> else n=Crabic(n,1);
> if(n==0||n==6174) break;
> }
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator