1 条题解

  • 1
    @ 2024-3-7 19:22:59

    模拟题,模拟手算10进制转xx进制即可。

    部分代码:

    void work(){
        stack<char> sta; // 用栈是因为最后要倒序输出
        while(n>=x){
            ll p=n%x;
            if(p<10)
                sta.push('0'+p); // 小于10,用数字表示
            else
                sta.push('A'+(p-10)); // 大于等于10,用字母表示
            n/=x;
        }
        if(n>0) // 处理最后剩下的n,如果n==0则不需要输出(不能有前导0)
            if(n<10) // 处理过程同上
                sta.push('0'+n);
            else
                sta.push('A'+(n-10));
        while(!sta.empty()) // 输出
            printf("%c",sta.top()),sta.pop();
    }
    主函数调用:work();
    
    • 1

    信息

    ID
    682
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    584
    已通过
    205
    上传者