Submission

Status:

PPPPPPP-P

Subtask/Task Score:

96/100

Score: 96

User: Tjeez

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-07 18:53:07

#include<iostream>
#include <cmath>
using namespace std; 
int main(){
	int b;
	string s1,s2;
	cin>>b>>s1>>s2;
	int a1=0,a2=0;
	for (int i=s1.length()-1;i>=0 ;i--){
		if (s1[i]>='0'&&s1[i]<='9'){
			a1+=pow(b,s1.length()-i-1)*(s1[i]-'0');	
		}
		else{
			a1+=pow(b,s1.length()-i-1)*(s1[i]-'A'+10);
		}
	}
	for (int i=s2.length()-1;i>=0 ;i--){
		if (s2[i]>='0'&&s2[i]<='9'){
			a2+=pow(b,s2.length()-i-1)*(s2[i]-'0');	
		}
		else{
			a2+=pow(b,s2.length()-i-1)*(s2[i]-'A'+10);
		}
	}
	int sm=a1+a2;
//	cout<<sm;
	string ans="";
	while (sm>0){
		int temp=sm%b;
		if (temp>=10){
			ans+='A'+temp-10;
		}
		else{
			ans+='0'+temp;
		}
		sm/=b;
	}
	for (int i=ans.length()-1 ; i>=0 ; i--){
		cout<<ans[i];
	}
}