2 条题解

  • 0
    @ 2025-12-13 19:16:43
    #include<bits/stdc++.h>
    using namespace std;
    
    int main() 
    {
        int n;
        cin>>n;
        
        for (int t = 0; t < n; t++) 
    	{
            int k;
            string s;
            cin >> k >> s;
            int ans = 0;
            int i = 0;
            while (s[i]) 
    		{  
                int d;
                if (s[i] <= '9')
    			{
    				d = s[i] - '0';
    			}
                else
    			{
    				d = s[i] - 'A' + 10;
            	}
                ans = ans * k + d;
                i++;
            }
        	cout<<ans<<"\n";
        }
        return 0;
    }
    
    
    • 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
      难度
      10
      标签
      递交数
      4
      已通过
      1
      上传者