1 solutions

  • 1
    @ 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

    Information

    ID
    2524
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    8
    Accepted
    3
    Uploaded By