-
Notifications
You must be signed in to change notification settings - Fork 0
/
1069.cpp
56 lines (51 loc) · 957 Bytes
/
1069.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/9/21.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
void to_array(int n,int arr[]){
for (int i=0; i<4; ++i) {
arr[i] = n % 10;
n /= 10;
}
}
int to_num(int num[]){
int ans = 0;
for (int i=0; i<4; ++i) {
ans = ans*10 + num[i];
}
return ans;
}
bool cmp(int a,int b){
return a > b;
}
int main(){
int n;
int a,b;
scanf("%d",&n);
int arr[5];
while (1) {
to_array(n, arr);
sort(arr, arr+4);
a = to_num(arr);
sort(arr, arr+4, cmp);
b = to_num(arr);
n = b-a;
printf("%04d - %04d = %04d\n",b,a,n);
if( n == 6174 || n == 0) break;
}
return 0;
}