Input a number to sort each number into a maximum number and a minimum number. The difference is used as the number of next operation until the difference is 0 or 6174 ..
This question is overcast. The input must be 4. Otherwise, Ole ..
Handle the number of less than four digits after the operation
# Include <cstdio> # include <algorithm> using namespace STD; int cant (INT s) {int A = s/1000; int B = s/100% 10; int c = s/10% 10; int d = S % 10; if (a = B & B = C & C = d) return 1; return 0;} int CAL (INT s) {int bn = s; int A [4]; A [0] = s/1000; A [1] = s/100% 10; A [2] = s/10% 10; A [3] = S % 10; int FL = 0; // indicates the number of digits in the high position is 0; if (a [0] = 0) {FL = 1; if (a [1] = 1) {FL = 2; if (A [2] = 0) FL = 3 ;}} sort (A, A + 4); int bnum, snum; snum = A [0] * 1000 + A [1] * 100 + A [2] * 10 + A [3]; // If (FL) = 0) {bnum = A [3] * 1000 + A [2] * 100 + A [1] * 10 + A [0];} else if (FL = 1) {bnum = A [3] * 100 + A [2] * 10 + A [1];} else if (FL = 2) {bnum = A [3] * 10 + A [2];} else {bnum = A [3];} printf ("% d-% d = % d \ n", bnum, snum, bnum-snum); Return bnum-snum;} int main () {int N; while (scanf ("% d", & N) & n! =-1) {printf ("n = % d: \ n", n); If (n> = 9999 | n <= 1000 | cant (n )) {// note that the input must be 4 digits !! Otherwise, Ole printf ("No !! \ N "); continue;} int times = 0; while (n! = 0 & n! = 6174) {times ++; n = CAL (n) ;}printf ("OK !! % D times \ n ", times);} return 0 ;}