E. Median String
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than tt.
Let's consider list of all strings consisting of exactly kk lowercase Latin letters, lexicographically not less than ss and not greater than tt (including ss and tt) in lexicographical order. For example, for k=2k=2, s=s="az" and t=t="bf" the list will be ["az", "ba", "bb", "bc", "bd", "be", "bf"].
Your task is to print the median (the middle element) of this list. For the example above this will be "bc".
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Input
The first line of the input contains one integer kk (1≤k≤2⋅1051≤k≤2⋅105) — the length of strings.
The second line of the input contains one string ss consisting of exactly kk lowercase Latin letters.
The third line of the input contains one string tt consisting of exactly kk lowercase Latin letters.
It is guaranteed that ss is lexicographically less than tt.
It is guaranteed that there is an odd number of strings lexicographically not less than ss and not greater than tt.
Output
Print one string consisting exactly of kk lowercase Latin letters — the median (the middle element) of list of strings of length kklexicographically not less than ss and not greater than tt.
Examples
input
Copy
2
az
bf
output
Copy
bc
input
Copy
5
afogk
asdji
output
Copy
alvuw
input
Copy
6
nijfvj
tvqhwp
output
Copy
qoztvz
题意:给你两个字符串,是用26进制排的
接下来问你大于第一个字符串,小于第二个字符串中的那些字符串中的中位数的字符串是什么
题解:
先从后往前把每个位置的数加起来放起来
然后从前往后除2进行输出
用java先MLE再TLE的血泪史
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
char a[maxn],b[maxn];
int c[maxn];
char ans[maxn];
int main()
{
int n;
cin>>n;
scanf("%s%s",a+1,b+1);
int x=0;
for(int i=n;i>=1;i--)
{
int k=a[i]-'a'+b[i]-'a'+x;
c[i]=k%26;
x=k/26;
// cout<<c[i]<<" "<<x<<endl;
}
for(int i=1;i<=n;i++)
{
int k=(c[i]+x*26);
ans[i]=char(k/2+'a');
cout<<ans[i];
x=k%2;
}
return 0;
}