http://codeforces.com/problemset/problem/1144/E
26进制,任意进制的做法
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 typedef long long ll; 7 int k; 8 char aa[200010]; 9 char bb[200010]; 10 int a[200010]; 11 int b[200010]; 12 int zz[200010]; 13 int ans[200010]; 14 int main() 15 { 16 cin >> k; 17 for (int i = 1; i <= k; i++) 18 { 19 cin >> aa[i]; 20 a[i] = int(aa[i] - 'a'); 21 } 22 for (int i = 1; i <= k; i++) 23 { 24 cin >> bb[i]; 25 b[i] = int(bb[i] - 'a'); 26 } 27 for (int i = k; i >=1; i--) 28 { 29 if (b[i] >= a[i]) 30 { 31 zz[i] = b[i] - a[i]; 32 } 33 else 34 { 35 zz[i] = b[i] + 26 - a[i]; 36 b[i - 1]--; 37 } 38 } 39 for (int i = 1; i <= k; i++) 40 { 41 if (zz[i] % 2 == 0) 42 { 43 ans[i] = zz[i] / 2; 44 } 45 else 46 { 47 ans[i] = (zz[i] - 1) / 2; 48 zz[i + 1] = zz[i + 1] + 26; 49 } 50 } 51 for (int i = k; i >= 1; i--) 52 { 53 if (ans[i] + a[i] >= 26) 54 { 55 ans[i] = ans[i] + a[i] - 26; 56 ans[i - 1]++; 57 } 58 else 59 { 60 ans[i] = ans[i] + a[i]; 61 } 62 } 63 for (int i = 1; i <= k; i++) 64 { 65 printf("%c", char(ans[i]+'a')); 66 } 67 return 0; 68 }