7-3 A-B 本題要求你計算A−B。不過麻煩的是,A和B都是字符串 ——
即從字符串A中把字符串B所包含的字符全刪掉,剩下的字符組成的就是字符串A−B。輸入格式: 輸入在2行中先後給出字符串A和B。兩字符串的長度都不超過10 4 ,並且保證每個字符串都是由可見的ASCII碼和空白字符組成,最後以換行符結束。 輸出格式: 在一行中打印出A−B的結果字符串。 輸入樣例: I love GPLT! It's a fun game! aeiou 輸出樣例: I lv GPLT! It's fn gm!
#include <iostream>
#include<string>
#include<iomanip>
#include<math.h>
#include <algorithm>
using namespace std;
int main()
{
string s1, s2, s3;
getline(cin, s1);
getline(cin, s2);
for (int i = 0; i < s1.length() ; i++)
{
bool count = 1;
for (int j = 0; j < s2.length() ; j++)
{
if (s2[j] == s1[i])
{
count = 0;
break;
}
}
if (count)
{
s3 += s1[i];
}
}
cout << s3;
return 0;
}