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 |
水题#include <iostream> #include <algorithm> using namespace std; int main() { while(1){ int N; cin >> N; if(N == -1) break; cout << "N=" << N << ":" << endl; if(N < 1000 || N > 9999 || N%1111 == 0){ cout << "No!!" << endl; continue; } int times = 0; while(N >= 1000 && N != 6174){ int digit[4]; digit[0] = N%10; digit[1] = (N/10)%10; digit[2] = (N/100)%10; digit[3] = (N/1000)%10; sort(digit, digit+4); int mx = 1000*digit[3]+100*digit[2]+10*digit[1]+digit[0]; int mn = 1000*digit[0]+100*digit[1]+10*digit[2]+digit[3]; cout << mx << '-' << mn << '=' << mx-mn << endl; N = mx-mn; times++; } if(N == 0 || N == 6174){ cout << "Ok!! " << times << " times" << endl; } else{ cout << "999-999=0" << endl; cout << "Ok!! " << times+1 << " 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