Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Patn01Z

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-07 20:21:02

#include <iostream>
#include <cmath>
#include <cctype>
using namespace std;

int toten(int b,string n){
    int sum=0;
    for(int i=0;i<n.length();i++){
        int temp=0;
        if(isdigit(n[i])){
            temp=n[i]-'0';
        }
        else{
            temp=n[i]-'A'+10;
        }
        
        sum=sum+temp*pow(b,n.length()-1-i);
    }
    return sum;
}

int main(){
    int b=2;
    string sn1;
    string sn2;
    int n1,n2;
    cin >> b >> sn1 >> sn2;
    n1=toten(b,sn1);
    n2=toten(b,sn2);
    int result=n1+n2;

    if(result==0){
        cout << 0;
        return 0;
    }
    
    string ans="";
    while (result>0){
        if(result%b<10){
            ans=char(result%b+'0')+ans;
        }
        else{
            ans=char(result%b-10+'A')+ans;
        }
        result=result/b;
    }
    
    
    cout << ans;

    return 0;
}