Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: pakorn

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-05 12:08:03

#include <bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int k,u=0,i=0;
	string n,m,ans;
	cin >> k;
	cin >> n >> m;
	for(auto s : n)
	{
		if(s >= 'A')s -= 'A' -10;
		else s -= '0';
		u  = u*k + s;
	}
	for(auto s : m)
	{
		if(s >= 'A')s -= 'A' -10;
		else s -='0';
		i  = i*k + s;
	}
	int t = u+i;
	if (t == 0) {
        cout << 0 << "\n";
        return 0;
    }
	while(t > 0)
	{
		int digit = t % k;
		if (digit < 10)
		    ans.push_back('0' + digit);
		else
		    ans.push_back('A' + digit - 10);

		t/=k;
	}
	reverse(ans.begin(),ans.end());
	cout << ans;
	return 0;
}