1 条题解

  • -2
    #include<iostream>
    #include<cmath>
    using namespace std;
    
    int chongzu_max(int n);
    int chongzu_min(int n);
    
    int main()
    {
        int n;
        cin>>n;
        int n2 = n;
        while(n2 != 495)
        {
            int n0 = chongzu_max(n2);
            int n1 = chongzu_min(n2);
            n2 = n0 - n1;
            cout<<n0<<" - "<<n1<<" = "<<n2<<endl; 
            if(n2 < 100 && n2 >= 10) n2 *= 10;
            if(n2 < 10) n *= 100;
            if(n2 == 0) return 0;
        }
        return 0;
    }
    
    int chongzu_max(int x)
    {
        int a = x % 10;
        x /= 10;
        int b = x % 10;
        x /= 10;
        int c = x % 10;
        int n[6];
        n[0] = a * 100 + b * 10 + c;
        n[1] = a * 100 + c * 10 + b;
        n[2] = b * 100 + a * 10 + c;
        n[3] = b * 100 + c * 10 + a;
        n[4] = c * 100 + a * 10 + b;
        n[5] = c * 100 + b * 10 + a;
        int max = 0;
        for(int i = 0; i <= 5; i++)
            if(n[i] > max) max = n[i];
        return max;
    }
    
    int chongzu_min(int x)
    {
        int a = x % 10;
        x /= 10;
        int b = x % 10;
        x /= 10;
        int c = x % 10;
        int n[6];
        n[0] = a * 100 + b * 10 + c;
        n[1] = a * 100 + c * 10 + b;
        n[2] = b * 100 + a * 10 + c;
        n[3] = b * 100 + c * 10 + a;
        n[4] = c * 100 + a * 10 + b;
        n[5] = c * 100 + b * 10 + a;
        int min = n[0];
        for(int i = 1; i <= 5; i++)
            if(n[i] < min) min = n[i];
        return min;
    }
    
  • 1

信息

ID
1193
难度
7
分类
(无)
标签
(无)
递交数
252
已通过
45
通过率
18%
被复制
14
上传者