题目链接:PAT A 1050
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 for any given strings. However, it might not be that simple to do it fast.
Sample Input:
They are students.
aeiou
Sample Output:
Thy r stdnts.
Hash:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string ss, sub;
int H[200] = {0};
while(getline(cin, ss))
{
getline(cin, sub);
for(int i = 0; i < sub.size(); ++i)
H[sub[i]] = 1;
for(int i = 0; i < ss.size(); ++i)
if(H[ss[i]] == 0) cout << ss[i];
cout << endl;
}
return 0;
}
String:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string ss, sub;
while(getline(cin, ss))
{
getline(cin, sub);
for(int i = 0; i < ss.size(); ++i)
if(sub.find(ss[i]) == string::npos)
cout << ss[i];
cout << endl;
}
return 0;
}