Submission

Status:

---------

Subtask/Task Score:

0/100

Score: 0

User: sssctngs

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-29 22:36:28

#include <iostream>

using namespace std;
int main(){
	
	int Base, num1, num2, p;
	string input;
	char hex[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
	cin >> Base >> input;
	int power = 1;
	for(int j = 0; j < input.size() - 1; j++)
	{
		p = j;
		power *= Base;
	}
	for(int j = 0; j <= p+1; j++)
	{
		if(input[j] >= 'A' && input[j] <= 'F')
		{num1 += (input[j] - 'A' + 10) * power;}
		else
		{num1 += (input[j] - '0') * power;}	
		power /= Base;
	}
	input = "";
	cin >> input;
	power = 1;
	for(int j = 0; j < input.size() - 1; j++)
	{
		p = j;
		power *= Base;
	}
	num2 = 0;
	for(int j = 0; j <= p+1; j++)
	{
		if(input[j] >= 'A' && input[j] <= 'F')
		{
			num1 += (input[j] - 'A' + 10) * power;
		}
		else
		{
		num2 += (input[j] - '0') * power;	
		}
		power /= Base;
		
	}
	int Answer = num1 + num2;
	string out = "";
	string Out = "";
	power = Base;
	while (Answer != 0)
	{
		out.push_back(hex[Answer % Base]);
		Answer -= Answer % Base;
		Answer /= Base;
	}
	for(int i = 0; i <= out.size(); i++)
	{
		Out.push_back(out[out.size() - i]);
	}
	cout << Out << "";
}