CodeForces - 1144E

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.InputThe 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 ttconsisting 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.OutputPrint one string consisting exactly of kklowercase Latin letters — the median (the middle element) of list of strings of length kklexicographically not less than ss and not greater than t.
Examples
Input
2
az
bf
Output
bc
Input
5
afogk
asdji
Output
alvuw
Input
6
nijfvj
tvqhwp
Output
qoztvz

这题很坑,转26进制吧,注意进位和余数的处理,代码实现(补题成功,吸收大佬的思想)

#include<cstdio>
#include<cstring>
int main(){
 int n;
 char a[20005],b[20005];
 int ans[20005];
 scanf("%d",&n);
 scanf("%s%s",a,b);
 int x,y;
 for(int i=n-1;i>=0;i--){
  x=a[i]-'a';
  y=b[i]-'a';
  if(y-x<0){
   b[i-1]--;
   y+=26;
  }
  if((y-x)%2==0){
   ans[i]=(y-x)/2;
  }
  else{
   ans[i]=(y-x)/2;
   ans[i+1]+=13;
  }
 }
 for(int i=n-1;i>=0;i--){
  x=a[i]-'a';
  ans[i-1]+=(x+ans[i])/26;
  ans[i]=(x+ans[i])%26;
 }
 for(int i=0;i<n;i++){
  printf("%c",'a'+ans[i]);
 }
 printf("\n");
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值