输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。

题目描述: 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”
思路:
(1)将字符串s2中的字符逐个存储在unordered_set中,
(2)然后在unordered_set中查找s1中的元素,
(3)若s1中的元素不在unordered_set中,将该元素插入到新的字符串result中。
(4)返回字符串result。
代码:

#include 
#include 
#include 
using namespace std;
string Delete(string& s1,string& s2)
{
    unordered_set m;
    for(int i=0;i

你可能感兴趣的:(刷题)