挺简单的,哈哈
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
int N; scanf("%04d", &N);
while (1) {
vector<int>part(4, 0);
int count = 0;
while (N != 0) {
part[count] =N%10;
N /= 10;
count++;
}
int first = 0, second = 0;
sort(part.begin(), part.end());
for (int i = 0; i < 4; i++) {
second += pow(10, 3 - i) * part[i];
first += pow(10, i) * part[i];
}
N = first - second;
printf("%04d - %04d = %04d\n", first, second, N);
if (N == 6174 || N == 0)
break;
}
return 0;
}