题意:
给定两个字符串S1和S2,将S = S1−S2定义为从S1提取S2中所有字符后的剩余字符串 �。 您的任务只是为任何给定的字符串计算S 1-S 2。 但是,快速进行操作可能不是那么简单。
输入规格:
每个输入文件包含一个测试用例。 每个案例由两行组成,分别给出S 1和S 2。 两个琴弦的琴弦长度不超过10 4。 保证所有字符都是可见的ASCII码和空白,并且换行符表示字符串的结尾。
输出规格:
对于每个测试用例,在一行中打印S 1-S 2。
输入样例:
They are students.
aeiou
样本输出:
Thy r stdnts.
思路:
用map<char,int> 来记录哪些字符在s2中出现过,出现过为标记为1,再遍历一遍s1,把没出现过的字符输出。
代码:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
int main()
{
string s1,s2;
getline(cin,s1);
getline(cin,s2);
map<char,int> m;
for(int i=0;i<s2.size();i++)
m[s2[i]]=1;
for(int i=0;i<s1.size();i++)
{
if(m[s1[i]]==0)
cout<<s1[i];
}
return 0;
}