L1-011 AB (20 points)
Topic description:
This problem requires you to calculate A-B. But the trouble is that both A and B are strings-that is, all the characters contained in string B are deleted from string A, and the remaining characters form string A−B.
Input format:
The input gives string A and B successively in 2 lines. The length of the two strings is not more than 104, and each string is guaranteed to be composed of visible ASCII codes and blank characters, and finally ends with a newline character.
Output format:
Print out the result string of A-B in one line.
Input sample:
I love GPLT! It’s a fun game!
aeiou
Sample output:
I lv GPLT! It’s fn gm!
Problem-solving ideas:
1024 Programmers' Day, write a water question to celebrate~ (mix a medal).
Customs clearance code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
string del;
int pos;
getline(cin, str);
getline(cin, del);
for (int i = 0; i < del.size(); i++) {
pos = str.find(del[i]);
while (pos != str.npos) {
str.erase(pos, 1);
pos = str.find(del[i]);
}
}
cout << str;
return 0;
}
Customs clearance screenshot: