首页 > 学院 > 开发设计 > 正文

1069. The Black Hole of Numbers (20)

2019-11-08 02:58:05
字体:
来源:转载
供稿:网友

没什么难度吧,注意输入元素几个特殊的就好了

#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()); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表