题目

Given two strings $S_1$ and $S_2$ , $S = S_1 - S_2$ is defined to be the remaining string after taking all the characters in $S_2$ from $S_1$ . Your task is simply to calculate $S_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 $S_1$ and $S_2$ , respectively. The string lengths of both strings are no more than $10^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 $S_1 - S_2$ in one line.

Sample Input:

1
2
They are students.
aeiou

Sample Output:

1
Thy r stdnts.

思路

这道题和乙级一些题很类似,如b1033。就是要去除s1中所有在s2中出现的字符。

虽然题目给的s2可能会很大,依旧只需统计某个字符是否出现,用int[128]的数组即可。

题目提到的“做到快并不简单”说的好像不是针对题目的测试点?可能说的是一般应用情景下的问题。测试点做到很快是很简单的。

代码

Github最新代码,欢迎交流

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

int main()
{
	char c, s1[10001];
	int s2[128] = {0};

	scanf("%[^\n]%c", s1, &c);
	while ((c = getchar()) != EOF && c != '\n')
		s2[(int)c] = 1;

	for (char *p = s1; *p; p++)
		if (!s2[(int)(*p)])
			putchar(*p);

	return 0;
}