6174 Problem time limit: +Ms | Memory Limit:65535KB 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
/* The end condition of the loop is that this four-digit number is 6174!!! */#include <stdio.h> #include <algorithm>using namespace Std;int main () {int I,test,n,k,cout,a[4];char s[4] ; scanf ("%d", &test), while (test--) {scanf ("%d", &n), Cout=1;while (n!=6174) {for (i=0;i<4;i++) {a[i]=n%10;n/ = 10;} Sort (a,a+4); k=a[0]*1000+a[1]*100+a[2]*10+a[3];n=a[3]*1000+a[2]*100+a[1]*10+a[0];n-=k;cout++;} printf ("%d\n", cout);} return 0;}
6174 questions (Nanyang Oj57)