Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
167564 | 赖泓君 | 进制数加法 | C++ | 解答错误 | 83 | 1 MS | 276 KB | 3307 | 2024-08-19 16:56:49 |
#include<bits/stdc++.h> using namespace std; int a1[5001],b1[5001],c[5001]; int main(){ int n; char a[5001],b[5001]; cin>>n>>a>>b; int len1=strlen(a); int len2=strlen(b); for(int i=1;i<=len1;i++){ if(a[len1-i]=='A') a1[i]=10; else if(a[len1-i]=='B') a1[i]=11; else if(a[len1-i]=='C') a1[i]=12; else if(a[len1-i]=='D') a1[i]=13; else if(a[len1-i]=='E') a1[i]=14; else if(a[len1-i]=='F') a1[i]=15; else if(a[len1-i]=='G') a1[i]=16; else if(a[len1-i]=='H') a1[i]=17; else if(a[len1-i]=='I') a1[i]=18; else if(a[len1-i]=='J') a1[i]=19; else if(a[len1-i]=='K') a1[i]=20; else if(a[len1-i]=='L') a1[i]=21; else if(a[len1-i]=='M') a1[i]=22; else if(a[len1-i]=='N') a1[i]=23; else if(a[len1-i]=='O') a1[i]=24; else if(a[len1-i]=='P') a1[i]=25; else if(a[len1-i]=='Q') a1[i]=26; else if(a[len1-i]=='R') a1[i]=27; else if(a[len1-i]=='S') a1[i]=28; else if(a[len1-i]=='T') a1[i]=29; else if(a[len1-i]=='U') a1[i]=30; else if(a[len1-i]=='V') a1[i]=31; else if(a[len1-i]=='W') a1[i]=32; else if(a[len1-i]=='X') a1[i]=33; else if(a[len1-i]=='Y') a1[i]=34; else if(a[len1-i]=='Z') a1[i]=35; else a1[i]=a[len1-i]-'0'; } for(int i=1;i<=len2;i++){ if(b[len1-i]=='A') b1[i]=10; else if(b[len1-i]=='B') b1[i]=11; else if(b[len1-i]=='C') b1[i]=12; else if(b[len1-i]=='D') b1[i]=13; else if(b[len1-i]=='E') b1[i]=14; else if(b[len1-i]=='F') b1[i]=15; else if(b[len1-i]=='G') b1[i]=16; else if(b[len1-i]=='H') b1[i]=17; else if(b[len1-i]=='I') b1[i]=18; else if(b[len1-i]=='J') b1[i]=19; else if(b[len1-i]=='K') b1[i]=20; else if(b[len1-i]=='L') b1[i]=21; else if(b[len1-i]=='M') b1[i]=22; else if(b[len1-i]=='N') b1[i]=23; else if(b[len1-i]=='O') b1[i]=24; else if(b[len1-i]=='P') b1[i]=25; else if(b[len1-i]=='Q') b1[i]=26; else if(b[len1-i]=='R') b1[i]=27; else if(b[len1-i]=='S') b1[i]=28; else if(b[len1-i]=='T') b1[i]=29; else if(b[len1-i]=='U') b1[i]=30; else if(b[len1-i]=='V') b1[i]=31; else if(b[len1-i]=='W') b1[i]=32; else if(b[len1-i]=='X') b1[i]=33; else if(b[len1-i]=='Y') b1[i]=34; else if(b[len1-i]=='Z') b1[i]=35; else b1[i]=b[len1-i]-'0'; } int len3=1; int x=0; while(len3<=len1||len3<=len2){ c[len3]=a1[len3]+b1[len3]+x; x=c[len3]/n; c[len3]%=n; len3++; } c[len3]=x; while(c[len3]==0&&len3>1){ len3--; } for(int i=len3;i>=1;i--){ if(c[i]==10) cout<<"A"; else if(c[i]==11) cout<<"B"; else if(c[i]==12) cout<<"C"; else if(c[i]==13) cout<<"D"; else if(c[i]==14) cout<<"E"; else if(c[i]==15) cout<<"F"; else if(c[i]==16) cout<<"G"; else if(c[i]==17) cout<<"H"; else if(c[i]==18) cout<<"I"; else if(c[i]==19) cout<<"J"; else if(c[i]==20) cout<<"K"; else if(c[i]==21) cout<<"L"; else if(c[i]==22) cout<<"M"; else if(c[i]==23) cout<<"N"; else if(c[i]==24) cout<<"O"; else if(c[i]==25) cout<<"P"; else if(c[i]==26) cout<<"Q"; else if(c[i]==27) cout<<"R"; else if(c[i]==28) cout<<"S"; else if(c[i]==29) cout<<"T"; else if(c[i]==30) cout<<"U"; else if(c[i]==31) cout<<"V"; else if(c[i]==32) cout<<"W"; else if(c[i]==33) cout<<"X"; else if(c[i]==34) cout<<"Y"; else if(c[i]==35) cout<<"Z"; else cout<<c[i]; } return 0; }