没什么难度吧,注意输入元素几个特殊的就好了
#include<iostream>#include<string>#include<algorithm>#PRagma warning(disable:4996)using namespace std;int main(){ string str; cin >> str; char temp[10]; sprintf(temp, "%04d", stoi(str));//如果输入元素不是一个4为的数字,前面补0 str = temp; if (str == "6174" || str == "0000")//特殊处理一开始就出现6174或0000 { string str1(str), str2(str); sort(str2.begin(), str2.end()); sort(str1.rbegin(), str1.rend()); char temp[10]; sprintf(temp, "%04d", stoi(str1) - stoi(str2)); str = temp; printf("%s - %s = %s/n", str1.c_str(), str2.c_str(), str.c_str()); } while (str != "6174" && str != "0000") { string str1(str), str2(str); sort(str2.begin(), str2.end()); sort(str1.rbegin(), str1.rend()); char temp[10]; sprintf(temp, "%04d", stoi(str1) - stoi(str2)); str = temp; printf("%s - %s = %s/n", str1.c_str(), str2.c_str(), str.c_str()); }}新闻热点
疑难解答