Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Brook

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-14 23:15:04

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a;
	string b;
	int h;
	cin>>a>>b;
	
	int la=a.length();
	int na[la];
	int tena=0;
	
	for(int i=0;i<la;i++){
		if(a[i]>=48 && a[i]<=57){
			na[i]=a[i]-48;
		}
		else if(a[i]>=65 && a[i]<=70){
			na[i]=a[i]-55;
		}
	}
	for(int i=0;i<la;i++){
		tena=tena+(na[i]*pow(n,la-1-i));
	}
	int lb=b.length();
	int nb[lb];
	int tenb=0;
	for(int i=0;i<lb;i++){
		if(b[i]>=48 && b[i]<=57){
			nb[i]=b[i]-48;
		}
		else if(b[i]>=65 && b[i]<=70){
			nb[i]=b[i]-55;
		}
	}
	for(int i=0;i<lb;i++){
		tenb=tenb+(nb[i]*pow(n,lb-1-i));
	}
	
	
	h=tena+tenb;
	if(h==0){
		cout<<h;
		return 0;
	}
	
	int y=0;
	int ans[100];
	while(h>0){
    	
		ans[y]=h%n;
    	h=h/n;
    	
    	y++;
	}
	for(int i=0;i<y;i++){
		if(ans[y-i-1]>=10 && ans[y-i-1]<=15){
			cout<<char(ans[y-i-1]+55);
		}
		else{
			cout<<ans[y-i-1];
		}
	}
	
	
	return 0;
}