#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
cin>>N;
int n[4],A,B;
while(true){
n[0]=N/1000;
n[1]=N/100%10;
n[2]=N/10%10;
n[3]=N%10;
sort(n,n+4,greater<int>());
A=n[0]*1000+n[1]*100+n[2]*10+n[3];
sort(n,n+4,less<int>());
B=n[0]*1000+n[1]*100+n[2]*10+n[3];
N=A-B;
printf("%04d - %04d = %04d\n",A,B,N);
if(N==6174 || N==0) break;
}
return 0;
}
PAT(Basic Level)_1019_数字黑洞
最新推荐文章于 2021-08-30 08:18:21 发布