1. 程式人生 > >31、刪除公共字元

31、刪除公共字元

(個人水平有限,請見諒!)

題目描述:

輸入兩個字串,從第一字串中刪除第二個字串中所有的字元。例如,輸入”They are students.”和”aeiou”,則刪除之後的第一個字串變成”Thy r stdnts.”

輸入描述:

每個測試輸入包含2個字串

輸出描述:

輸出刪除後的字串

輸入:

They are students.
aeiou

輸出:

Thy r stdnts.

程式碼示例:

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str,del;
    getline(cin,str);
    getline(cin,del);
    
    for (int i = 0; i < del.length(); i++)
        for (int j = 0; j < str.length(); j++)
            if (del[i] == str[j])
                str.erase(j--,1);
    
    cout << str;
}