PAT 1069

来源:互联网 发布:启动mysql 编辑:程序博客网 时间:2024/05/19 17:47

PAT 1069

技巧题

#include <cstdio>#include <iostream>#include <cmath>#include <algorithm>#include <string>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;}