版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:[https://blog.csdn.net/weixin\_42449444/article/details/88782967](https://blog.csdn.net/weixin_42449444/article/details/88782967)
Given two strings
and
, S =
−
is defined to be the remaining string after taking all the characters in
from
. Your task is simply to calculate
−
for any given strings. However, it might not be that simple to do it fast.
Each input file contains one test case. Each case consists of two lines which gives
and
, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.
For each test case, print
−
in one line.
They are students.
aeiou
Thy r stdnts.
这道水题跟【GPLT】L1-011 A-B 可以说是一模一样的,上次我是用map求解的,那这次就用set来玩下吧。在字符串A中删除字符串B中含有的字符后输出字符串A-B。换个角度来想就是只输出字符串A中字符串B不含有的字符。
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2;
getline(cin,s1);
getline(cin,s2);
set<int> s; //记录s2中的字符
for(auto it : s2)
{
s.insert(it);
}
for(auto it : s1)
{
if(s.count(it) == 0) //避免输出s2中的字符
{
cout << it;
}
}
return 0;
}