分析:码农题,照这模拟就行,高精度的B进制,注意字符串反转的技巧。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <vector> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <bitset> 10 #include <cmath> 11 #include <queue> 12 #include <stack> 13 using namespace std; 14 const int maxn=2200; 15 char s[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; 16 int n; //进制 17 int vis1[maxn],vis2[maxn]; 18 int ans[maxn]; 19 int main() 20 { 21 while(cin>>n) 22 { 23 string a,b; 24 cin>>a; 25 cin>>b; 26 memset(vis1,0,sizeof(vis1)); 27 memset(vis2,0,sizeof(vis2)); 28 int len1=a.length(); //反转第一个串 29 for(int i=0;i<len1/2;i++){ 30 char temp=a[i]; 31 a[i]=a[len1-1-i]; 32 a[len1-1-i]=temp; 33 } 34 for(int i=0;i<len1;i++){ 35 int pos; 36 for(int j=0;j<36;j++){ 37 if(a[i]==s[j]){ 38 pos=j; break; 39 } 40 } 41 vis1[i]=pos; 42 } 43 int len2=b.length(); //反转第二个串 44 for(int i=0;i<len2/2;i++){ 45 char tt=b[i]; 46 b[i]=b[len2-i-1]; 47 b[len2-1-i]=tt; 48 } 49 for(int i=0;i<len2;i++){ 50 int pos; 51 for(int j=0;j<36;++j){ 52 if(b[i]==s[j]){ 53 pos=j; break; 54 } 55 } 56 vis2[i]=pos; 57 } 58 int mx=max(len1,len2); 59 int cnt=0; 60 for(int i=0;i<mx;i++){ 61 int temp=vis1[i]+vis2[i]+cnt; 62 if(temp>=n){ 63 cnt=1; 64 ans[i]+=temp%n; 65 }else{ 66 cnt=0; 67 ans[i]+=temp; 68 } 69 } 70 if(cnt==1){ 71 ans[mx]=1; ++mx; 72 } 73 string ss; 74 for(int i=0;i<mx;i++){ 75 ss+=s[ans[i]]; 76 } 77 for(int i=0;i<mx/2;i++){ 78 char yy=ss[i]; 79 ss[i]=ss[mx-i-1]; 80 ss[mx-i-1]=yy; 81 } 82 cout<<ss<<endl; 83 } 84 return 0; 85 }