作者: 陈越
单位: 浙江大学
时间限制: 150 ms
内存限制: 64 MB
代码长度限制: 16 KB
本题要求你计算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!
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
string str1, str2;
char *temp = new char[10000];
int x = 0;
getline(cin, str1);
vector<char>input1(str1.size());
getline(cin, str2);
vector<char>input2(str2.size());
copy(str1.begin(), str1.end(), input1.begin());
copy(str2.begin(), str2.end(), input2.begin());
for (int i = 0; i < (int)str2.size(); i++)
{
for (int j = 0; j < (int)str1.size(); j++)
{
if (input2[i] == input1[j])
{
temp[x] = input2[i];
x++;
}
}
}
for (int i = 0; i < x; i++)
input1.erase(remove(input1.begin(), input1.end(), temp[i]), input1.end());
for (int i = 0; i < (int)input1.size(); i++)
cout << input1[i];
return 0;
}