2 条题解

  • 0
    @ 2025-3-26 19:25:41

    用短除法。

    #include<bits/stdc++.h>
    using namespace std;
    string card="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ans="";
    int main(){
        int n,m;
        cin>>n>>m;
        if(n==0){
            cout<<0;
            return 0;
        }
        while(n>=1){
            int tmp=n%m;
            ans+=card[tmp];
            n/=m;
        }
        reverse(ans.begin(),ans.end());
        cout<<ans;
    }
    
    
    • -1
      @ 2024-10-27 20:32:45
      #include <bits/stdc++.h>
      using namespace std;
      
      int d;//十进制数字
      string r;//结果
      int x;//进制
      string zh = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      
      int main()
      {
          cin>>d>>x;
          while(d !=0)
          {
              //cout<<d % x<<endl;
              r = zh[d % x]+ r;
              d  =  d / x;
          }
          cout<<r<<endl;
          return 0;
      }
      
      • 1

      信息

      ID
      4635
      时间
      1000ms
      内存
      128MiB
      难度
      2
      标签
      递交数
      39
      已通过
      24
      上传者