6174 Problem time limit:MS | Memory limit:65535 KB Difficulty:2
-
Describe
-
Let's say you have a four-digit number that each has a different number, you get a after all the numbers from the big to the small, you get B from small to large, and then you replace the number with a-a, and you continue to do so. For example, starting from 1234, you can get 4321-1234=3087, 8730-378=8352, 8532-2358=6174, and then back to its own! Now you need to write a program to determine how many times a four-digit number of such operations can occur, and the number of times the operation is calculated
For example, input 1234 execution order is 1234->3087->8352->6174->6174, output is 4
-
Input
-
The first line is N, which represents the n set of test data.
The next n lines each write a four-digit number that each of you has a different number.
-
Output
-
How many times does the action described above appear to loop
-
Sample input
-
11234
-
Sample output
-
4
-
Source
-
[Zhang Jie] Original
-
Uploaded by
-
Zhang Jie
#include <iostream> #include <stdio.h> #include <algorithm>using namespace std;void fun (int m,int a[]) { int count=0; while (m>0) { a[count++]=m%10; M=M/10; } Sort (a,a+count);} int main () { int n,m; int a[100]; cin>>n; while (n--) { int t=0; cin>>m; while (1) {fun (m,a); t++; M= (A[3]*1000+a[2]*100+a[1]*10+a[0])-(a[0]*1000+a[1]*100+a[2]*10+a[3]); if (m==6174) break ; } cout<<t+1<<endl; } return 0;}
Nanyang Polytechnic---6174 problems