原题:1069. The Black Hole of Numbers (20)
解题思路:
按题意做即可。
代码如下:
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
char s[10];
while(scanf("%s", s) == 1)
{
int a, b, c = 1;
a = atoi(s);
sprintf(s, "%04d", a);
sort(s, s+4);
b = atoi(s);
reverse(s, s+4);
a = atoi(s);
while(c != 0 && c != 6174)
{
c = a - b;
printf("%04d - %04d = %04d\n", a, b, c);
sprintf(s, "%04d", c);
sort(s, s+4);
b = atoi(s);
reverse(s, s+4);
a = atoi(s);
}
}
return 0;
}