PAT 1069

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;

}








全部评论

相关推荐

12-19 22:04
武汉大学 Java
点赞 评论 收藏
分享
想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务