Sicily 1194. Message Flood

For study!

Posted by Winray on March 4, 2016
  • 思路:
    • 不区分大小写,先全部转化为小写,用stl提供的函数做会很方便。
  • 具体代码如下:
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
    int n, m;
    while (cin >> n && n) {
        cin >> m;
        set<string> v;
        for (int i = 0; i < n; i++) {
            string temp;
            cin >> temp;
            for (int j = 0; j < temp.size(); j++) {  //全部转化为小写 
                temp[j] = tolower(temp[j]);
            }
            v.insert(temp);
        }
        for (int i = 0; i < m; i++) {
            string temp;
            cin >> temp;
            for (int j = 0; j < temp.size(); j++) {
                temp[j] = tolower(temp[j]);
            }
            if (v.count(temp))
                v.erase(temp); 
        }
        cout << v.size() << endl;
    }
    
    return 0;
}