AcWing 1555. 数字黑洞
原题链接
简单
作者:
leo123456
,
2020-08-31 11:03:39
,
所有人可见
,
阅读 561
//字符的insert操作,往前面插入字符
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(char a,char b) {
return a > b;
}
int main()
{
string s;
cin >> s;
s.insert(0, 4 - s.length(), '0');
do {
string a = s, b = s;
sort(a.begin(), a.end(),cmp);
sort(b.begin(), b.end());
int result = stoi(a) - stoi(b);
s = to_string(result);
s.insert(0, 4 - s.length(), '0');
cout << a << " - " << b << " = " << s << endl;
} while (s != "6174"&&s != "0000");
return 0;
}