1 solutions

  • 0
    @ 2025-10-31 10:51:47
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
        int a, c;//输入数据a,遍历c次对应位数相加
        int b = 1;//存储是几位数
        double d = 0;//输出的数据
        int e = 0;//用于存储每次便利的取余数
        int f = 0;//存储为10的倍数时,后面几个0
        cin>>a;
        //遍历是几位数
        for(int i = 1;i > 0;i++){
            int mi = pow(10,i);
            if(a/mi != 0){
                b++;
            }else{
                break;
            }
        }
        //当是一位数时的输出
        if(b == 1){
            cout<<0<<a<<endl;
            return 0;
        }
        c = b;
        //两位及以上位数时的输出
        for(int x = 1;x <= c;x++){
            int mx = pow(10,x);
            int mb = pow(10,b);
            //(a-e)保证要的对应位数的后面是0或者没有
            // (a-e) % mx取到对应位数的数字
            //(a-e) % mx * mb / mx去除两位以上取余时后面的0,并且变为调换后的对应位数的10倍数
            d = d + (a-e) % mx * mb / mx ;
            if(d == 0){
                f++;
            }
            e = a%mx;
            b--;
        }
        //如果后面有0则将0在前面打印
        for(int o = 1;o <= f;o++){
            cout<<0;
        }
        cout<<d<<endl;
        return 0;
    }
    
    • 1

    Information

    ID
    404
    Time
    1000ms
    Memory
    64MiB
    Difficulty
    3
    Tags
    # Submissions
    155
    Accepted
    78
    Uploaded By