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
题意:给你两个长度为n的字符串然后求位于它两中间的字符串
思路:把字母转换成26进制情况然后模拟加法,和除法(准确的说是除二)。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define LL long long
using namespace std;
const int maxn=2e5+100;
char s[maxn],t[maxn];
int a[maxn],b[maxn];
int ans[maxn];
int main()
{
int n;
scanf("%d",&n);
scanf("%s%s",s+1,t+1);
for(int i=1;i<=n;i++)
{
a[i]=s[i]-'a';
b[i]=t[i]-'a';
}
for(int i=n;i>=1;i--)
{
//cout<<a[i]<<" "<<b[i]<<endl;
a[i]+=b[i];
if(a[i]>=26)
{
a[i-1]+=a[i]/26;
a[i]%=26;
}
//cout<<a[i]<<" ";
}
//cout<<a[0];
for(int i=0;i<=n;i++)
{
ans[i]=a[i]/2;
//cout<<ans[i]<<" "<<a[i]<<endl;
int mod=a[i]%2;
a[i+1]+=mod*26;
}
for(int i=1;i<=n;i++)
{
printf("%c",ans[i]+'a');
}
printf("\n");
return 0;
}