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 |
写完之后,我凌乱了....第一次 CE,第二次是OLE,第三次是WA.第四次是AC............ 然后我凌乱了.....不过是0MS哦....秀一下代码: #include <iostream> #include <cmath> #include <cstdlib> using namespace std; int cmpj(const void *a,const void *b) { return (*(int*)b-*(int*)a); } int cmps(const void *a,const void *b) { return (*(int*)a-*(int*)b); } int main() { int n,result=1,temp1,temp2,test,k=0,t,j,m; while (cin>>n&&n!=-1) { k=0; t=0; j=0; m=0; result=n; cout<<"N="<<n<<":"<<endl; if((result<1000)||(result>=10000)) { cout<<"No!!"<<endl; m++; } else{ while(result!=6174&&result!=0) { int b[4]={0}; test=result; if(result>=1000) t=4; else if(result>=100) t=3; else if(result>=10) t=2; else if(result>0) t=1; for(int i=0;i<t;i++) { b[i]=test/(pow(10.0,t-1-i)); test=test-b[i]*(pow(10.0,t-1-i)); } qsort(b,4,sizeof(b[0]),cmpj); if(b[0]==b[1]&&b[2]==b[3]&&b[1]==b[2]) { cout<<"No!!"<<endl; j++; break; } else { temp1=b[0]*pow(10.0,t-1)+b[1]*pow(10.0,t-2)+b[2]*pow(10.0,t-3)+b[3]; } qsort(b,4,sizeof(b[0]),cmps); temp2=b[0]*1000+b[1]*100+b[2]*10+b[3]; result=temp1-temp2; k++; cout<<temp1<<"-"<<temp2<<"="<<result<<endl; } } if(j==0&&m==0) cout<<"Ok!! "<<k<<" times"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator