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 |
大牛们帮我看看这个程序,总是wa#include<cstdio> #include<algorithm> using namespace std; int k; void change(int m,int *a) { k=0; while(m) { a[k++]=m%10; m/=10; } } int main() { int m,a[20],i,j,min,max,an,count,f; while(1) { scanf("%d",&m); printf("N=%d:\n",m); if(m==-1) break; if(m%1111==0||m<1000||m>9999) { printf("No!!\n"); } else { count=0; an=m; while(1) { change(an,a); sort(a,a+k); max=min=0; for(i=0,j=k-i-1;i<k;i++,j--) { min=min*10+a[i]; max=max*10+a[j]; } an=max-min; count++; printf("%d-%d=%d\n",max,min,an); if(an==0||an==6174) break; } printf("Ok!! %d times\n",count); } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator