Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: FIrmTInn

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-10 09:13:53

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,len_1,len_2, val = 0,count = 0;
    cin >> n;
    string str1, str2;
    char ans[1000];
    cin >> str1;cin >> str2;
    len_1 = str1.length(), len_2 = str2.length();
    int exp1 = len_1-1, exp2 = len_2-1;
    for(int i=0;i<len_1;i++){
        if(str1[i] >= '0' && str1[i] <= '9'){
            val += (int(str1[i] - '0')*pow(n,exp1));
        }
        else if(str1[i] >= 'A' && str1[i] <= 'Z'){
            val += ((int(str1[i]-'A')+10)*pow(n,exp1));
        }
        exp1--;
    }
    for(int i=0;i<len_2;i++){
        if(str2[i] >= '0' && str2[i] <= '9'){
            val += (int(str2[i] - '0')*pow(n,exp2));
        }
        else if(str2[i] >= 'A' && str2[i] <= 'Z'){
            val += ((int(str2[i]-'A')+10)*pow(n,exp2));
        }
        else if(str2[i] >= 'a' && str2[i] <= 'z'){
            val += ((int(str2[i]-'a')+10)*pow(n,exp2));
        }
        exp2--;
    }
    if(val == 0){
        cout << 0;
        return 0;
    }
    for(int i=val;i>0;i/=n){
        if(i%n >=10){
            ans[count] = char(((i%n) - 10) + 'A');
        }
        else{
        ans[count] = char('0' + (i%n));
        }
        count++;
    }
    for(int i = count-1;i>=0;i--){
        cout << ans[i];
    }


    return 0;
}