提交时间:2024-08-20 14:43:40
运行 ID: 168915
#include <bits/stdc++.h> using namespace std; int n,a1[301],b1[301],t,c1[301]; char a[301],b[301]; int change(char c){ if(c >= '0' && c <= '9') return c - 48; else if(c == 'A') return 10; else if(c == 'B') return 11; } int main(){ cin >> n >> a >> b; t = max(strlen(a),strlen(b)); for(int i = 0;i < strlen(a);i++) a1[strlen(a) - i] = change(a[i]); for(int i = 0;i < strlen(b);i++) b1[strlen(b) - i] = change(b[i]); for(int i = 1;i <= t;i++){ c1[i] += (a1[i] + b1[i]); c1[i + 1] += c1[i] / n; c1[i] %= n; } bool ch; for(int i = (t + 1);i > 0;i--){ if(i == (t + 1) && c1[i] == 0) continue; cout << c1[i]; } return 0; }