PAT Advanced 1050. String Subtraction (20) (C语言实现)
题目
Given two strings
Input Specification:
Each input file contains one test case. Each case consists of two lines which
gives
Output Specification:
For each test case, print
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;
}