2 solutions

  • 2
    @ 2025-5-24 15:35:03
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL trans(string s,int x)
    {
    	//reverse(s.begin(),s.end());
    	LL res=0;
    	//cout<<s<<endl;
    	for(int i=0;i<s.size();i++)
    	{
    		int t=0;
    		if(s[i]>='0'&&s[i]<='9')
    		{
    			t=s[i]-'0';	
    		}	
    		else
    		{
    			t=s[i]-'A'+10;
    		}
    		res=res*x+t;
    	//	cout<<t<<endl;
    	//	cout<<res<<endl; 
    	}	
    	return res;
    } 
    int main()
    {
    	int T;
    	cin>>T;
    	while(T--)
    	{
    		int x;
    		string s;
    		cin>>x>>s;
    		cout<<trans(s,x)<<endl; 
    	}
    	return 0;
    }
     
    
    • 1
      @ 2026-2-4 9:25:41
      
      
      • 1

      Information

      ID
      2524
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      9
      Tags
      (None)
      # Submissions
      12
      Accepted
      5
      Uploaded By