提交时间:2024-08-19 20:48:13

运行 ID: 167926

#include <bits/stdc++.h> using namespace std; const int N = 100; int ans1,ans2,n,ans; int Change_to_10(int len,string a) { int sum = 0,p = 0; for(int i = len - 1; i >= 0; i--) { if(a[i] >= '0' && a[i] <= '9') { sum += (a[i] - '0') * pow(n,p); } else if(a[i] >= 'A' && a[i] <= 'Z') { sum += (a[i] - 'A' + 10) * pow(n,p); } else { sum += (a[i] - 'a' + 10) * pow(n,p); } ++p; } return sum; } void Change_to_N(int x) { int a[500] = {0},l = 0; if(x == 0) { printf("0"); return; } while(x != 0) { a[++l] = x % n; x /= n; } for(int i = l; i >= 1; i--) { if(a[i] >= 10) { char ch = 'A'; ch += a[i] - 10; printf("%c",ch); } else { printf("%d",a[i]); } } } int main() { string a,b; scanf("%d %s %s",&n,&a,&b); ans1 = Change_to_10(a.size(),a); ans2 = Change_to_10(b.size(),b); ans = ans1 + ans2; Change_to_N(ans); return 0; }