Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题

Posted by KatrineYang at 2016-09-09 21:01:34 on Problem 1350
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator