把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了。
但是这样会有一个问题就是串的长度有2e5,26的2e5次方显然不可求,所以需要对每一位进行手动的加和运算。
对于两个串,我们假设a串从后往前的每一位对应的数值为a0, a1, a2...,b串从后往前的每一位对应的数值为b0, b1, b2...对于进制加法,有
扔一下垃圾代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define ll long long
#define lowbit(x) (x&(-x))
#define PI acos(-1)
#define ms(x,y) memset(x, y, sizeof(x))
using namespace std;
const int maxn = 2e5+7;
char a[maxn], b[maxn];
int ans[maxn];
int main()
{
int n;
scanf("%d", &n);
scanf("%s%s", a, b);
for(int i=n-1;i>=0;i--)
{
int ta = a[i] - 'a';
int tb = b[i] - 'a';
ans[i] = ta + tb;
if(ans[i]&1)
{
ans[i+1] += 13;
ans[i] = (ans[i] - 1) / 2;
ans[i] += ans[i+1] / 26;
ans[i+1] %= 26;
}
else ans[i] = ans[i] / 2;
}
for(int i=0;i<n;i++) printf("%c", 'a' + ans[i]); puts("");
}