#include <iostream>
using namespace std;
int main() {
int num, n[5] = { 0 }, i, m,si=100000,liu=100000;
printf("请输入一个五位正整数:");
cin >> num;
for (i = 0; i < 5; i++) {
n[i] = num % 10;
num /= 10;
}
for (int a = 0; a < 5; a++) {
for (int b = 0; b < 5; b++) {
if (b == a) continue;
for (int c = 0; c < 5; c++) {
if (c == a || c == b) continue;
for (int d = 0; d < 5; d++) {
if (d == a || d == b || d == c) continue;
for (int e = 0; e < 5; e++) {
if (e == a || e == b || e == c || e == d) continue;
m = n[a] * 10000 + n[b] * 1000 + n[c] * 100 + n[d] * 10 + n[e];
//列出所有含这五个数的数
if ((m>40000&&((m - 40000) <= si-40000))||(m<=40000&&(40000-m)<=si-40000)) {
si = m;
}
if ((m > 60000 && ((m - 60000) <= liu-60000)) || (m <= 60000 && ( 60000-m) <= liu-60000)) {
liu = m;
}
}
}
}
}
}
cout << si << " " << liu;
return 0;
}