提交时间:2024-08-19 23:03:47

运行 ID: 168147

#include<bits/stdc++.h> using namespace std; int n; string a,b; int s[1000005]; int main() { cin>>n>>a>>b; s[0]=max(a.size(),b.size())+1; for(int i=1;i<=s[0];i++) { if(i<=a.size()) { if(a[a.size()-i]>='0'&&a[a.size()-i]<='9') { s[i]+=a[a.size()-i]-'0'; } else { s[i]+=a[a.size()-i]-'A'+10; } } if(i<=b.size()) { if(b[b.size()-i]>='0'&&b[b.size()-i]<='9') { s[i]+=b[b.size()-i]-'0'; } else { s[i]+=b[b.size()-i]-'A'+10; } } s[i+1]+=s[i]/n; s[i]%=n; } while(s[s[0]]==0) { s[0]--; } for(int i=s[0];i>=1;i--) { if(s[i]>9) { cout<<char(s[i]+55); } else { cout<<s[i]; } } return 0; }