Submission

Status:

---------

Subtask/Task Score:

0/100

Score: 0

User: HawThorns

Problemset: บวกเลขฐาน

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-13 17:20:36

#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 shortest = toin.str1[0].size();
       if(toin.str1[0].size() > toin.str1[1].size())
              shortest = toin.str1[1].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 < shortest;i++){
              int total = extratoadd;
              for(int k = 0; k < 2;k++){
                     int num = 0;
                     if(toin.str1[k][i] >= 'A')
                            num = toin.str1[k][i] - 'A' + 10;
                     else
                            num = toin.str1[k][i] - '0';
                     total += num;
              }
              if(total >= input)
                     extratoadd += total / input;
              else
                     extratoadd = 0;
              toprint.push_back(total % input);
       }
       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;
}