题目描述
易错点
第一行可能为空,用getline判断是否为空;若为空,直接输出即可
知识点
应该用一个数组建一个哈希映射,快速判断该键是否能用,我直接用set了
代码
#include <iostream>
#include <set>
#include <string>
#include <istream>
using namespace std;
int main(){
string badChar,test;
//getline可以读取一个空行
getline(cin,badChar);
cin >> test;
set<char> st;
bool flag = true;//判断+键是否能用
if(badChar.size() == 0){
cout << test << endl;
return 0;
}
for(char e : badChar){
if(e>='A' && e<='Z')
st.insert('a'+e-'A');
if(e == '+'){
flag =false;
}
st.insert(e);
}
for(char e : test){
if(e>='A' && e<='Z'){
if(flag && st.find(e) == st.end()){
cout << e;
}
}
else{
if(st.find(e)==st.end()){
cout << e;
}
}
}
cout << endl;
return 0;
}