首页 > 其他分享 >1093 字符串A+B——20分

1093 字符串A+B——20分

时间:2022-09-02 10:56:25浏览次数:46  
标签:输出 20 1093 list ls1 字符串 输入

给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除。

输入格式:
输入在两行中分别给出 A 和 B,均为长度不超过 10​6​​ 的、由可见 ASCII 字符 (即码32~126)和空格组成的、由回车标识结束的非空字符串。

输出格式:
在一行中输出题面要求的 A 和 B 的和。

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk

| 代码长度限制 | 时间限制 | 内存限制 |
| 16KB | 400ms | 64MB |

思路:Life is short, I need Python

代码:

ls1 = list(input() + input()) # 将输入的字符串A和B连接起来并转换成列表
ls1 = sorted(list(set(ls1)), key=ls1.index) # 对列表进行去重处理但是内部元素仍然保持原本的排列顺序
for each in ls1:
    print(each, end='')

标签:输出,20,1093,list,ls1,字符串,输入
From: https://www.cnblogs.com/Fare-well/p/16649042.html

相关文章