1 条题解

  • 0
    @ 2026-1-28 14:29:05
    #include<bits/stdc++.h>
    using namespace std;
    
    int main(){
        int n; // [1] 输入的三位正整数
        cin>>n; // [2] 读取输入的三位数
    
        int g=n%10; // [3] g:提取个位数字(对10取余)
        int s=n/10%10; // [4] s:提取十位数字(除以10后对10取余)
        int b=n/100%10; // [5] b:提取百位数字(除以100后对10取余)
    
        // [6] 比较个位、十位、百位的大小,找出最大值与最小值并计算差值
        if(g>=s && s>=b){
            cout<<g-b; // 最大值为g,最小值为b
        }else if(g>=b && b>=s){
            cout<<g-s; // 最大值为g,最小值为s
        }else if(s>=b && b>=g){
            cout<<s-g; // 最大值为s,最小值为g
        }else if(s>=g && g>=b){
            cout<<s-b; // 最大值为s,最小值为b
        }else if(b>=g && g>=s){
            cout<<b-s; // 最大值为b,最小值为s
        }else{
            cout<<b-g; // 最大值为b,最小值为g
        }
        return 0;
    }
    
    • 1

    信息

    ID
    1129
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    1
    已通过
    1
    上传者