6747 数字黑洞
#include<bits/stdc++.h> #define f(i,s,e) for(int i = s; i <= e; i++) #define ll long long using namespace std; const int N = 1e3+10,inf = 0x3f3f3f3f; int main() { int n,ans = 0; //ans次数 cin >> n; while(n != 495) { int a = n % 10; //个位 int b = n / 10 % 10; //十位 int c = n / 100; //百位 if(a < b) swap(a,b); //swap:交换两个变量的值 if(a < c) swap(a,c); if(b < c) swap(b,c); //经过这三次swap,可以保证a > b > c int maxx = a * 100 + b * 10 + c; int minn = c * 100 + b * 10 + a; n = maxx - minn; ans++; } cout << ans; return 0; }