Submission

Status:

PPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: HawThorns

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-13 17:30:15

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct inputsBase{
       string str1[2] = {"I was in hell, looking at heaven","-Jane Doe"};
};


int main(){
       int input;
       vector<int> toprint;
       //cout << "Base ";
       cin >> input;
       struct inputsBase toin;
       for(int i = 1; i <= 2;i++){
              //cout << "Num"<< i << " ";
              cin >> toin.str1[i-1];
       }
       int longest = toin.str1[1].size();
       if(toin.str1[0].size() > toin.str1[1].size())
              longest = toin.str1[0].size();
       reverse(toin.str1[0].begin(),toin.str1[0].end());
       reverse(toin.str1[1].begin(),toin.str1[1].end());
       int extratoadd = 0;
       for(int i = 0; i < longest;i++){
              int total = extratoadd;
              for(int k = 0; k < 2;k++){
                     int num = 0;
                     if(toin.str1[k].size() > i)
                            if(toin.str1[k][i] >= 'A')
                                   num = toin.str1[k][i] - 'A' + 10;
                            else if(toin.str1[k][i] >= '0' && toin.str1[k][i] <= '9')
                                   num = toin.str1[k][i] - '0';
                     else
                            num = 0;
                     total += num;
              }
              if(total >= input)
                     extratoadd = total / input;
              else
                     extratoadd = 0;
              toprint.push_back(total % input);
       }

       if(extratoadd > 0){
              toprint.push_back(extratoadd);
       }
       reverse(toprint.begin(),toprint.end());
       //cout << "OUTPUT ";
       for(const int &num : toprint){
              if(num >= 10){
                     cout << char('A' + num - 10);
              }
              else
                     cout << num;
       }
       return 0;
}