题目
思路
题目大意:把s2中出现的字符从s1中删除,并不需要真的删除,只要对s2中的每个字符做上标记,遍历s1时如果某个字符标记过不输出就可以了;
题目虽然简单,但还是有两个知识点的;
1、gets函数不能通过编译,要使用 cin.getline(字符数组名,字符长度,结束符),其中结束符默认为 \n;
fetchar(); //读取多余字符,包括回车和空格;
getline(cin, string); //读取一行到string中,可以读取回车;
2、阿斯克码表一共有128个字符,包括可见的不可见的,最后一个是 delete;
代码
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;
int main()
{
char s1[100000], s2[100000];
bool exist[200];
fill(exist, exist + 200, true);
cin.getline(s1, 100000);
cin.getline(s2, 100000);
int a = strlen(s1), b = strlen(s2);
//将s2中的字符标记为不存在,即不能输出
for(int i = 0; i < b; i ++){
exist[s2[i]] = false;
}
for(int i = 0; i < a; i ++){
//如果存在才会输出
if(exist[s1[i]] == true) printf("%c", s1[i]);
}
system("pause");
return 0;
}