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.

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 kk lexicographically not less than ss and not greater than tt.

example

Input
2
az
bf
Output
bc
Input
5
afogk
asdji
Output
alvuw
Input
6
nijfvj
tvqhwp
Output
qoztvz

今天练习赛的一道题,大意为给定两个字符串,按字典序取中间的字符串,如az和bf,依次为az,ba,bb,bc,bd,be,bf,所以输出bc。
这个题我开始的想法是得出给定两字符串之间相差然后除二再对第一个字符串直接进行操作,结果样例事都过了,但是不知道为什么第六组数据被卡了,也没找到到底是哪里出了问题,后来再倒过头去仔细想了想,其实就是转了个26进制出来,但是转进制这方面的知识点被卡了,找了个模板套上了
后来结束了回来又扒拉了一下,整理了一下,也去网上看了看大佬的代码
AC码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
 
char s1[200005];
char s2[200005];
int a[200005];
 
inline int getv(char ch)
{
	return ch-'a';
}
 
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;i++)
		a[i]=getv(s1[i])+getv(s2[i]);
	for(int i=n;i>=2;i--)
	{
		a[i-1]+=a[i]/26;
		a[i]%=26;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]&1)
			a[i+1]+=26;
		putchar('a'+a[i]/2);
	}
	putchar('\n');
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值