題目地址:1194. Message Flood
思路:
不區分大小寫,先全部轉化為小寫,用stl提供的函數做會很方便。
具體代碼如下:
1 #include <iostream>
2 #include <set>
3 #include <string>
4 using namespace std;
5
6 int main() {
7 int n, m;
8 while (cin >> n && n) {
9 cin >> m;
10 set<string> v;
11 for (int i = 0; i < n; i++) {
12 string temp;
13 cin >> temp;
14 for (int j = 0; j < temp.size(); j++) { //全部轉化為小寫
15 temp[j] = tolower(temp[j]);
16 }
17 v.insert(temp);
18 }
19 for (int i = 0; i < m; i++) {
20 string temp;
21 cin >> temp;
22 for (int j = 0; j < temp.size(); j++) {
23 temp[j] = tolower(temp[j]);
24 }
25 if (v.count(temp))
26 v.erase(temp);
27 }
28 cout << v.size() << endl;
29 }
30
31 return 0;
32 }