美文网首页
B1069 The Black Hole of Numbers

B1069 The Black Hole of Numbers

作者: Tsukinousag | 来源:发表于2020-02-14 23:27 被阅读0次

    B1069 The Black Hole of Numbers (20分)

    //注意数字处理时不足四位补上前导0.

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <math.h>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <stack>
    #define lowbit(i)((i)&(-i))
    using namespace std;
    typedef long long ll;
    const int MAX=3e5+10;
    const int INF=0x3f3f3f3f;
    const int MOD=1000000007;
    const int SQR=632;//633块,632
    bool cmp(char a,char b)
    {
        return a>b;
    }
    bool cmp2(char a,char b)
    {
        return a<b;
    }
    string change(int n)
    {
        string ans="";
        while(n>0)
        {
           char c=n%10+'0';
           ans+=c;
           n/=10;
        }
        while(ans.size()<4)
            ans='0'+ans;
        return ans;
    }
    int change2(string x)
    {
        int sum=0;
        for(int i=0;i<x.size();i++)
        {
            sum=sum*10+x[i]-'0';
        }
        return sum;
    }
    int main()
    {
        int n;
        string a,b,temp;
        scanf("%d",&n);
        int t=n;
        while(1)
        {
        temp=change(t);
        sort(temp.begin(),temp.end(),cmp);
        a=temp;
        printf("%04d",change2(a));
        printf(" - ");
        sort(temp.begin(),temp.end(),cmp2);
        b=temp;
        printf("%04d",change2(b));
        printf(" = ");
        t=change2(a)-change2(b);
        printf("%04d\n",t);
        if(t==6174||t==0)
            break;
        }
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:B1069 The Black Hole of Numbers

          本文链接:https://www.haomeiwen.com/subject/bipsfhtx.html