题目

Given two strings S1S_{1} and S2,S=S1S2S_{2}, S=S_{1}-S_{2} is defined to be the remaining string after taking all the characters in S2S_{2} from S1S_{1}. Your task is simply to calculate S1S2S_{1}-S_{2} for any given strings. However, it might not be that simple to do it fast.

Input Specification:

Each input file contains one test case. Each case consists of two lines which gives S1S_1 and S2S_2, respectively. The string lengths of both strings are no more than 10410^4. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

Output Specification:

For each test case, print S1S2S_{1}-S_{2} in one line.

Sample Input:

1
2
They are students.
aeiou

Sample Output:

1
Thy r stdnts.

题解

思路

  • 对第一行字符串的每个字符,如果它不在第二行当中,那么就输出它。
  • 很显然用哈希集合。

数据结构

  • a是第一行,字符串
  • b是一个哈希集和,存放第二行每一个字符。

算法

  • 先输入第一行
  • 再输入第二行,建哈希集和
  • 对每一个第一行的字符,判断其在不在第二行,不在就输出,注意后面不加空格。

代码

  • 因为使用Python能够AC,因此只放了Python的代码。
1
2
3
4
5
6
a = input()
b = set([i for i in input()])
for i in a:
if i not in b:
print(i, end='')