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<iostream> #include<cmath> using namespace std; int changel(int n) { int a[4],i,j,k,temp,m,count=4; a[0]=n/1000; a[1]=(n-a[0]*1000)/100; a[2]=(n-a[0]*1000-a[1]*100)/10; a[3]=n%10; if(a[3]==0) { count--; if(a[2]==0) { count--; if(a[1]==0) count--; } } for(i=4-count;i<4;i++) { for(j=i+1,k=i;j<4;j++) if(a[k]>a[j]) k=j; temp=a[k]; a[k]=a[i]; a[i]=temp; } m=1000*a[0]+100*a[1]+10*a[2]+a[3]; return m; } int changeh(int n) { int a[4],i,j,k,temp,m,count=4; a[0]=n/1000; a[1]=(n-a[0]*1000)/100; a[2]=(n-a[0]*1000-a[1]*100)/10; a[3]=n%10; if(a[0]==0) { count--; if(a[1]==0) { count--; if(a[2]==0) count--; } } if(a[0]==a[1]&&a[2]==a[3]&&a[1]==a[2]) return -1; for(i=4-count;i<4;i++) { for(j=i+1,k=i;j<4;j++) if(a[k]<a[j]) k=j; temp=a[k]; a[k]=a[i]; a[i]=temp; } m=1000*a[0]+100*a[1]+10*a[2]+a[3]; return m; } int main() { int n,temp,count=0,highest; cin>>n; while(n!=-1) { if((int)log10(double(n))+1!=4) { cout<<"N="<<n<<':'<<endl; cout<<"No!"<<endl; } else { highest=changeh(n); cout<<"N="<<n<<':'<<endl; if(highest<0) { cout<<"No!! "<<endl; } else { temp=n; while(temp!=6174&&temp!=0) { cout<<changeh(temp)<<'-'<<changel(temp)<<'='; temp=changeh(temp)-changel(temp); cout<<temp<<endl; count++; } cout<<"Ok!! "<<count<<" times"<<endl; count=0; } } cin>>n; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator