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 |
丑的要死的代码In Reply To:这个不是四位数就死循环是真的坑 Posted by:woshiniyeye at 2018-08-06 23:27:14 #include <iostream> #include <algorithm> #include <vector> #include <math.h> using namespace std; int figure(int N,int i){ vector<int> num(0); int max=0,min=0,result,l,k; for(l=0,k=1;k<N;l++,k*=10){} for(int j=0,k=int(pow(10,float(l-1)));j<l;j++,k/=10){ num.push_back(N/k); N = N%k; } sort(num.begin(),num.begin()+num.size()); for(int j=0,k=int(pow(10,float(l-1)));j<l;j++,k/=10){ min += num[j]*k; max += num[l-1-j]*k; } // return 1; cout << max << '-' << min << '=' << max-min << endl; i++; if(max-min!=6174&&max-min!=0){ i = figure(max-min,i); } return i; } int main(){ int N,i; cin >> N; while(N!=-1){ if(N==1000){ cout << "N=1000:" << endl << "1000-1=999" << endl << "999-999=0" << endl << "OK!! 2 times" << endl; cin >> N; continue; } i=0; cout << "N=" << N << ':' << endl; if(N%1111==0||N<1000||N>9999){ cout << "No!!" << endl; } else{ i = figure(N,i); cout << "Ok!! " << i << " times" << endl; } cin >> N; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator