1050 String Subtraction

给2个字符串,要求输出S1-S2,结果不能出现S2中出现的字符。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string.h>
using namespace std;

char s1[10001], s2[10001];
int main() {
cin.getline(s1, 10001);
cin.getline(s2, 10001);
int len1 = strlen(s1);
int len2 = strlen(s2);
bool ASCII[300] = {false};
for (int i = 0; i< len2; i++) {
ASCII[s2[i]] = true;
}
for (int i = 0; i < len1; i++) {
if (ASCII[s1[i]] == false) {
printf("%c", s1[i]);
}
}

return 0;
}

// 因为输入会有空格,所以用cin.getline()来读取一行,用scanf遇到空格会停止

They are students.
aeiou

Thy r stdnts.