I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution:

for _ in range(int(input())):
a = input() + '['
b = input() + '[' output = ""
for _ in range(len(a) + len(b) - 2):
if a < b:
output += a[0]
a = a[1:]
else:
output += b[0]
b = b[1:] print(output)

Please note: '[' is the first char after 'Z'.

HackerRank "Morgan and a String"的更多相关文章

  1. HackerRank beautiful string

    问题 https://vjudge.net/problem/HackerRank-beautiful-string 给一个字符串S,可以任意取走S中的两个字符从而得到另外一个字符串P,求有多少种不同的 ...

  2. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  3. *[hackerrank]Lexicographic paths

    https://www.hackerrank.com/contests/w9/challenges/lexicographic-steps 这题还是折腾很久的.题目意思相当于,比如有两个1两个0,那么 ...

  4. *[hackerrank]Sam and sub-strings

    https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...

  5. [hackerrank]The Love-Letter Mystery

    https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery 简单题. #include <cstdlib& ...

  6. *[hackerrank]ACM ICPC Team

    https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team 这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过 ...

  7. Hackerrank 2020 February 2014 解题报告

    Hackerrank 2020 February 2014 解题报告 比赛链接 Sherlock and Watson (20分) 题意:给定一个数组,向右平移K次,然后有Q个询问,问第x位置上是几 ...

  8. hackerrank:Almost sorted interval

    题目链接:https://www.hackerrank.com/challenges/almost-sorted-interval 题目大意: 定义一个“几乎单调”区间(区间最小值在最左面,最大值在最 ...

  9. 【转】morgan stanley 电面面经新鲜出炉

    楼楼早上上午大概11点接到的电话,一个声音炒鸡好听的GG,说他是来自morgan stanley的,想和我约一下店面时间.我一听,真是戳不及防,掐指一算,online的IKE测试已经过去20几天了吧, ...

随机推荐

  1. R语言决策树分类模型

    rm(list=ls()) gc() memory.limit(4000) library(corrplot) library(rpart) data_health<-read.csv(&quo ...

  2. Codeforces Round #301 (Div. 2) B. School Marks

    其实是很水的一道bfs题,昨晚比赛的时候没看清题意,漏了一个条件. #include<cstdio> #include<cstring> #include<iostrea ...

  3. ZOJ 1113 u Calculate e

    原题链接 题目大意:迭代求自然常数e. 解法:没什么好说的,注意数据类型和输出格式. 参考代码: #include<stdio.h> #include<math.h> int ...

  4. php部分---对数据的多条件查询,批量删除

    1.给多条件查询,添加条件 <h1>新闻信息查看</h1> <?php $tiaojian1=" 1=1"; $tiaojian2=" 1= ...

  5. jQuery显示隐藏动态效果的几种写法

    <script type="text/javascript"> $(document).ready(function() {     /*$("#test1& ...

  6. Codeforces Round #128 (Div. 2)

    A. Two Problems 分两题的过题情况讨论,并且数值均不大,暴力枚举. B. Game on Paper 每次给格子染色后,考虑当前格子在正方形中的位置,然后判断对应的正方形是否都已染色. ...

  7. nginx配置说明

    #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log notice; #error ...

  8. c语言学习笔记

    为什么需要输出控制符: 1:  01组成的代码可以表示数据亦可以表示指令: 2:如果01组成的代码表示的是数据的话,那么同样的01代码组合以不同的输出格式输出就会有不同的输出结果.. %d   --- ...

  9. UMDH

    1. 什么是UMDH UMDH=User Mode dump heap.把进程的堆dump下来.包括堆栈信息.UMDH是WinDbg附带的一个工具. 2. 下载安装 WinDbg.完事后在WinDbg ...

  10. HTTPS-透彻学习汇总

    SSL和SSH和OpenSSH,OpenSSL有什么区别 一.SSL的作用 不使用SSL/TLS的HTTP通信,就是不加密的通信.所有信息明文传播,带来了三大风险. 窃听风险(eavesdroppin ...