提交时间:2023-08-11 20:49:18
运行 ID: 24440
#include<iostream> #include<vector> char ch[36]; int x; using namespace std; vector<int> add(vector<int> &A,vector<int> &B){ if(A.size()<B.size()) return add(B,A); vector<int> C; int t = 0; for(int i=0;i<A.size();i++){ t+=A[i]; if(i<B.size()) t+=B[i]; C.push_back(t%x); t/=x; } if(t) C.push_back(t); return C; } int main(){ for(int i = 0; i < 10; i++) ch[i] = i + '0'; for(int i = 0; i < 26; i++) { ch[i+10] = i + 'A'; //cout << ch[i] << " "; } string a,b; vector<int> A,B; cin>>x>>a>>b; for(int i=a.size()-1;i>=0;i--) { if(a[i] >= '0' && a[i] <= '9') A.push_back(a[i]-'0'); else A.push_back(a[i]-'A'+10); } for(int i=b.size()-1;i>=0;i--) { if(b[i] >= '0' && b[i] <= '9') B.push_back(b[i]-'0'); else B.push_back(b[i]-'A'+10); } auto c = add(A,B); for(int i=c.size()-1;i>=0;i--) cout<<ch[c[i]]; return 0; }