Problem Description:
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.
Input Specification:
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.
Output Specification:
For each test case, print − in one line.
Sample Input:
They are students.
aeiou
Sample Output:
Thy r stdnts.
解题思路:
这道水题跟【GPLT】L1-011 A-B 可以说是一模一样的,上次我是用map求解的,那这次就用set来玩下吧。在字符串A中删除字符串B中含有的字符后输出字符串A-B。换个角度来想就是只输出字符串A中字符串B不含有的字符。
AC代码:
#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;
}