本题要求你计算A-B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A-B。
输入格式:
输入在2行中先后给出字符串A和B。两字符串的长度都不超过104,并且保证每个字符串都是由可见的ASCII码和空白字符组成,最后以换行符结束。
输出格式:
在一行中打印出A-B的结果字符串。
输入样例:I love GPLT! It's a fun game! aeiou输出样例:
I lv GPLT! It's fn gm!
输入带空格的字符串:
string str;getline(cin,str);
或者
char string [256];
gets (string); // 输入
头文件:#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
bool com(char a,string b){
int i;
for(i=0;i<b.length();i++)
if(a==b[i])return true;
return false;
}
int main(){
string a ,b;
getline(cin,a);
getline(cin,b);
int i;
for(i=0;i<a.length();i++){
if(com(a[i],b)!=true){
cout<<a[i];
}
}
cout<<endl;
return 0;
}
#include <string>
using namespace std;
bool com(char a,string b){
int i;
for(i=0;i<b.length();i++)
if(a==b[i])return true;
return false;
}
int main(){
string a ,b;
getline(cin,a);
getline(cin,b);
int i;
for(i=0;i<a.length();i++){
if(com(a[i],b)!=true){
cout<<a[i];
}
}
cout<<endl;
return 0;
}