1 条题解

  • 0
    @ 2025-9-6 13:38:22

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
     
    typedef long long LL;
    LL convert(int p, string s) {
        LL ans=0;
        reverse(s.begin(),s.end());
        for(int i=0; i<s.size(); i++) {
            if(s[i]>='A') ans+=(s[i]-'A'+10)*pow(p,i);
            else ans+=(s[i]-'0')*pow(p,i);
        }
        return ans;
    }
     
    int main() {
        int T;
        cin>>T;
        while(T--) {
            int p;
            string s;
            cin>>p>>s;
            cout<<convert(p,s)<<endl;
        }
        return 0;
    }
     
    /*
    in:
    2
    8 1362
    16 3F0
    out:
    754
    1008
    */
    
    • 1

    信息

    ID
    5534
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者