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 kk lexicographically not less than ss and not greater than tt.
Examples
2
az
bf
bc
5
afogk
asdji
alvuw
6
nijfvj
tvqhwp
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 }
Median String的更多相关文章
- Codeforces Round #550 (Div. 3) E. Median String (模拟)
Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- E. Median String 解析(思維、大數運算)
Codeforce 1144 E. Median String 解析(思維.大數運算) 今天我們來看看CF1144E 題目連結 題目 給你兩個長度為\(k\)的字串\(s\)和\(t\),求字典序排序 ...
- Median String CodeForces - 1144E
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is le ...
- Codeforces Round #550 (Div. 3)E. Median String
把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了.但是这样会有一个问题就是串的长度有2e ...
- Codeforces 1144 E. Median String
原题链接:https://codeforces.com/problemset/problem/1144/E tag:字符串模拟,大整数. 题意:给定两个字符串,求字典序中间串. 思路:可以把这个题当做 ...
- Codeforces Round #550 (Div. 3) E. Median String (思维,模拟)
题意:给你两个字符串\(s\)和\(t\),保证\(t\)的字典序大于\(s\),求他们字典序中间的字符串. 题解:我们假设题目给的不是字符串,而是两个10禁止的正整数,那么输出他们之间的数只要把他两 ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- CF550 DIV3
A - Diverse Strings CodeForces - 1144A A string is called diverse if it contains consecutive (adjace ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
- Google 面试题:Java实现用最大堆和最小堆查找中位数 Find median with min heap and max heap in Java
Google面试题 股市上一个股票的价格从开市开始是不停的变化的,需要开发一个系统,给定一个股票,它能实时显示从开市到当前时间的这个股票的价格的中位数(中值). SOLUTION 1: 1.维持两个h ...
随机推荐
- 关于tomcat8在windows2008下高并发下有关问题的解决方案
关于tomcat8在windows2008下高并发下问题的解决方案 因为客户服务器特殊的环境问题,只能使用windows2008r2服务器,然而配置过后,网站的高访问量很快就出现了各种问题,以下是解决 ...
- 文件服务器 — File Browser
前言 一直想部署一套文件服务器,供队友之间相互传输文件.平时用微信发送文件真的太烦了,每发送或者接收一次都会有一个新的文件,造成重复文件太多了.文件服务器统一管理,自己需要什么文件再下载. 前面也安装 ...
- 18V转5V,15V转5V的LDO和DC芯片方案
18V 转 5V, 15V 转 5V 的 LDO:芯片的选择,特别是输入电压,在低电平 5V 以下的,基本上都是接近也可以.但是 5V 以上,如现在的 18V 和 15 的话,就不一样了.我们需要在选 ...
- 边框 display属性 盒子模型 浮动 溢出 定位 z-index
目录 边框 隐藏属性 钓鱼网站 display visibility 盒子模型 调整方式 浮动 溢出 圆形头像的制作 定位 z-index属性 边框 /*border-left-width: 5px; ...
- 使用腾讯云部署war包
目录 1.前期准备 2.springboot打war包 3.部署war包 4.导入数据库 5.修改Tomcat启动端口 6.启动服务器 7.设置腾讯云服务器防火墙规则 8.从外部访问 9.总结 10. ...
- 中国蚁剑 - AntSword
中国蚁剑 - AntSword 中国蚁剑是一种跨平台操作工具,它主要提供给用户用于有效的网络渗透测试以及进行正常运行的网站. 否则任何人不得将网站用于其无效用途以及可能的等目的.自己承担并追究其相关责 ...
- day13-功能实现12
家居网购项目实现012 以下皆为部分代码,详见 https://github.com/liyuelian/furniture_mall.git 29.功能27-Ajax检验注册名 29.1需求分析/图 ...
- linux配置本地yum源实现在局域网中在线安装软件包
安装linux下安装软件需要安装一系列的rpm包,用rpm -ivh xx和yum install xx 如果用rpm安装软件包的时候,需要自己下载rpm安装包,如果rpm包不全总是提示依赖检查失败或 ...
- python进阶之路20 正则表达式 re模块
正则表达式前情 案例:京东注册手机号校验 基本需求:手机号必须是11位.手机号必须以13.15.17.18.19开头.必须是纯数字 '''纯python代码实现''' # while True: # ...
- DVWA靶场实战(四)——File Inclusion
DVWA靶场实战(四) 四.File Inclusion: 1.漏洞原理: 随着网站的业务的需求,程序开发人员一般希望代码更加灵活,所以将被包含的文件设置为变量,用来进行动态调用,但是正是这种灵活性通 ...