1. 程式人生 > 其它 >【pta】L1-011 A-B (20 分) <刪除字串指定字元><板子題>

【pta】L1-011 A-B (20 分) <刪除字串指定字元><板子題>

一、題目大意

題目連結:https://pintia.cn/problem-sets/994805046380707840/problems/994805130426171392

本題要求你計算AB。不過麻煩的是,A和B都是字串 —— 即從字串A中把字串B所包含的字元全刪掉,剩下的字元組成的就是字串AB。

輸入格式:

輸入在2行中先後給出字串A和B。兩字串的長度都不超過104,並且保證每個字串都是由可見的ASCII碼和空白字元組成,最後以換行符結束。

輸出格式:

在一行中打印出AB的結果字串。

輸入樣例:

I love GPLT!  It's a fun game!
aeiou
結尾無空行

輸出樣例:

I lv GPLT!  It's  fn gm!
結尾無空行

二、ac程式碼

#include "iostream"
#include "algorithm"
using namespace std;

int main()
{
    string t,s;
    getline(cin,t);
    getline(cin,s);
    for (auto it:s)
    {
        t.erase(remove(t.begin(),t.end(),it),t.end());
    }
    cout<<t;
    return 0;
}

板子題,沒啥好說的,需要記住erase和remove結合用法