Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手看看为什么wrong?

Posted by power721 at 2009-10-04 20:05:40 on Problem 1350
#include<stdio.h>
#include<algorithm>
main()
{int n,c,a,b,i,f,j,k,s[4];
while(scanf("%d",&n)&&n!=-1)
{c=0;
printf("N=%d\n",n);
while(1)
{f=a=b=i=j=0;
k=1;
while(n)
	s[i++]=n%10,n/=10,j++;
std::sort(s,s+j);
for(i=0;i<j;i++)
	a+=s[i]*k,b+=s[j-i-1]*k,k*=10;
n=a-b;
c++;
if(!n&&c==1||(c==1&&j!=4))
	{puts("No!!"),f=1;break;}
printf("%d-%d=%d\n",a,b,n);
if(n%6174==0)break;
}
if(!f)printf("Ok!! %d times\n",c);
}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator