7-3 A-B (20 分)
本题要求你计算A−B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A−B。
输入格式:
输入在2行中先后给出字符串A和B。两字符串的长度都不超过10
4
,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。
输出格式:
在一行中打印出A−B的结果字符串。
输入样例:
I love GPLT! It’s a fun game!
aeiou
输出样例:
I lv GPLT! It’s fn gm!
1.set
if(w.find(a[i])==w.end() ) p.push(a[i]);
while(!p.empty()){
printf("%c",p.front());
p.pop();
}
#include<cstdio>
#include<cstring>
#include<set>
#include<queue>
using namespace std;
char a[10000+10];
int main(){
char c;
queue<char> p;
set<char> w;
int t=0,i;
while((c=getchar())!=EOF&&c!='\n'){
a[t]=c;
t++;
}
while((c=getchar())!=EOF&&c!='\n'){
w.insert(c);
}
for(i=0;i<t;i++){
if(w.find(a[i])==w.end() ) p.push(a[i]);
}
while(!p.empty()){
printf("%c",p.front());
p.pop();
}
return 0;
}
for(i=0;i<t1;i++){
if(book[a[i]]==1) continue;
printf("%c",a[i]);
}
#include<cstdio>
#include<cstring>
using namespace std;
char a[10000+10];
int book[300];
int main(){
char c;
int t1=0,i;
while((c=getchar())!=EOF&&c!='\n'){
a[t1]=c;
t1++;
}
while((c=getchar())!=EOF&&c!='\n'){
book[c]=1;
}
for(i=0;i<t1;i++){
if(book[a[i]]==1) continue;
printf("%c",a[i]);
}
return 0;
}