Submission

Status:

-------P-

Subtask/Task Score:

12/100

Score: 12

User: cj

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-05 09:31:22

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

int main(){
	int n;
	int h = 0;
	int h2 = 0;
	stack<int> s;
	string a,b;
	cin>>n>>a>>b;
	for(int i=0;i<a.length();i++){
		if(a[i] <= '9'){
			h = h*n+a[i]-'0';
		}else{
			h = h*n+(a[i] -'A'+10);
		}
	}
	for(int i=0;i<b.length();i++){
		if(b[i] <= '9'){
			h2 = h2*n+b[i]-'0';
		}else{
			h2 = h2*n+(b[i] -'A'+10);
		}
	}
	int as = h+h2;
	while(as > 0){
		s.push(as%n);
		as /= n;
	}
	if (as == 0) cout << 0;
	while(!s.empty()){
		if(s.top() <= 9){
			cout<<s.top();
		}else{
			cout<<char(s.top()-10+'A');
		}
		s.pop();
	}
	return 0;
}