Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: limsan20122

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-01 17:10:11

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x=0;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    int e=0;
    int f=0;
    int g=0;
    int h=0;
    int k=0;
    string y;
    string z;
    cin >> x >> y >> z;
    for(int i=0;i<y.length();i++){
        if(y[i]=='A')  b=10;
        else if(y[i]=='B') b=11;
        else if(y[i]=='C') b=12;
        else if(y[i]=='D') b=13;
        else if(y[i]=='E') b=14;
        else if(y[i]=='F') b=15;
        else b=(y[i]-'0');
        a+=((pow(x,y.length()-i-1))*b);
    }
    for(int i=0;i<z.length();i++){
        if(z[i]=='A')  c=10;
        else if(z[i]=='B') c=11;
        else if(z[i]=='C') c=12;
        else if(z[i]=='D') c=13;
        else if(z[i]=='E') c=14;
        else if(z[i]=='F') c=15;
        else c=(z[i]-'0');
        d+=(pow(x,z.length()-i-1)*c);
    }   
    e=a+d; 
    f=e;
    while(1){
        if((f/x)>0){
            g++;
        }else{
            break;
        }
        f=f/x;
    }
    g=g+1;
    for(int i=g-1;i>=0;i--){
        h=(pow(x,i));
            if((e/h)==10) cout << "A";
            else if((e/h)==11) cout << "B";
            else if((e/h)==12) cout << "C";
            else if((e/h)==13) cout << "D";
            else if((e/h)==14) cout << "E";
            else if((e/h)==15) cout << "F";
            else cout << e/h;
          e=e%h;  
    }
    return 0;
}