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 (1k21051≤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.

Examples

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

题意:给你两个只含有小写字母的字符串, s和t,保证s的字典序比t小。把s和t看成一个26进制的数,让你输出这两个数的中位数。
思路:首先把两个字符串的每一个位上的数值加起来,然后向前进位(从尾部开始)
然后从头开始遍历加起来的那个数值,如果数值为偶数,那么中位数的这一位就是数值/2,如果是奇数,那么中位数的这一位是/2且向下取整。
并把那个多余的一加到下一位中,(注意上一位的1到下一位是26)。
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 using namespace std;
 8 int main()
 9 {
10 int n;
11 char str1[200005],str2[200005];
12 int a[200005];
13 scanf("%d",&n);
14 cin.get();
15 scanf("%s",str1);
16 cin.get();
17 scanf("%s",str2);
18 int flag=0;
19 for(int i=n-1;i>=0;i--)
20     {
21         int sum=str1[i]-'a'+str2[i]-'a'+flag;//flag做标记,进行满26进一
22         if(sum>=26&&i!=0)//第一位不用进一,到时候直接除以二就行
23         {
24             flag=1;
25             a[i]=sum-26;
26         }
27         else {
28            flag=0;
29            a[i]=sum;
30         }
31     }
32     for(int i=0;i<n;i++)
33         if(a[i]%2)
34     {
35         a[i+1]=a[i+1]+26;
36         a[i]/=2;
37     }
38     else
39         a[i]/=2;
40     for(int i=0;i<n;i++)
41         printf("%c",a[i]+'a');
42     printf("\n");
43     return  0;
44 }

 

全部评论

相关推荐

程序员牛肉:主要是因为小厂的资金本来就很吃紧,所以更喜欢有实习经历的同学。来了就能上手。 而大厂因为钱多,实习生一天三四百的就不算事。所以愿意培养你,在面试的时候也就不在乎你有没有实习(除非是同级别大厂的实习。) 按照你的简历来看,同质化太严重了。项目也很烂大街。 要么换项目,要么考研。 你现在选择工作的话,前景不是很好了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务