PTA A_1069 The Black Hole of Numbers
传送门:https://pintia.cn/problem-sets/994805342720868352/problems/994805400954585088解:
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
char s;
int n1, n2, n3;
scanf("%d", &n3);
do
{
sprintf(s, "%04d", n3);
sort(s, s + 4);
sscanf(s, "%d", &n2);
reverse(s, s + 4);
sscanf(s, "%d", &n1);
printf("%04d - %04d = %04d\n", n1, n2, n3 = n1 - n2);
}while(n3 && n3 != 6174);
return 0;
}
页:
[1]