Sicily 1194 Message Flood

題目地址:http://soj.me/1194

題目說名字是不區分大小寫的,用map數據結構記錄那個人有沒有發短信給他,然後就可以很快搞定

#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
  int a, b;
  while (cin >> a) {
    if (!a)
      break;
    cin >> b;
    string name[20001];
    for (int i = 0; i < a; i++) {
      string temp;
      cin >> temp;
      for (int j = 0; j < temp.length(); j++)
        temp[j] = tolower(temp[j]);
      name[i] = temp;
    }
    map<string, bool> nm;
    for (int i = 0; i < b; i++) {
      string temp;
      cin >> temp;
      for (int j = 0; j < temp.length(); j++)
        temp[j] = tolower(temp[j]);
      nm[temp] = true;
    }
    int count = 0;
    for (int i = 0; i < a; i++)
      if (!nm[name[i]])
        count++;
    cout << count << endl;
  }
  return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章