Sicily 1938. Message Flood

1938. Message FloodConstraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Well, how do you feel about mobile phone? Your answer would probably be something like that “It’s so convenient and benefits people a lot”. However, if you ask Merlin this question on the New Year’s Eve, he will definitely answer “What a trouble! I have to keep my fingers moving on the phone the whole night, because I have so many greeting messages to send! ”. Yes, Merlin has such a long name list of his friends, and he would like to send a greeting message to each of them. What’s worse, Merlin has another long name list of senders that have sent message to him, and he doesn’t want to send another message to bother them (Merlin is so polite that he always replies each message he receives immediately). So, before he begins to send messages, he needs to figure to how many friends are left to be sent. Please write a program to help him. Here is something that you should note. First, Merlin’s friend list is not ordered, and each name is alphabetic strings and case insensitive. These names are guaranteed to be not duplicated. Second, some senders may send more than one message to Merlin, therefore the sender list may be duplicated. Third, Merlin is known by so many people, that’s why some message senders are even not included in his friend list.

Input

There are multiple test cases. The first line contains an integer T, indicating the number of test cases. In each case, at the first line there are two numbers n and m (1<=n, m<=20000), which is the number of friends and the number of messages he has received. And then there are n lines of alphabetic strings (the length of each will be less than 10), indicating the names of Merlin’s friends, one per line. After that there are m lines of alphabetic strings, which are the names of message senders.

Output

For each case, print one integer in one line which indicates the number of left friends he must send.

Sample Input15 3 Inkfish Henry Carp Max Jericho Carp Max Carp Sample Output

3

#include <queue>#include <iostream>#include <stdio.h>#include <map>#include <algorithm>#include <string>using namespace std;string to_up(string a) {for (int i = 0; i < (int)a.size(); i++) {a[i] = a[i] >= 'a' ? a[i] – ('a' – 'A') : a[i];}return a;}int main() {std::ios::sync_with_stdio(false);string temp;int counter, case_num, n_list, n_sent;cin >> case_num;while (case_num–) {map<string, bool> list;//千万注意map在while中声明,,可以避免初始化带来的问题map<string, bool> :: iterator ll;counter = 0;cin >> n_list >> n_sent;while (n_list–) {cin >> temp;temp = to_up(temp);list.insert(pair<string, bool>(temp, true));}while (n_sent–) {cin >> temp;temp = to_up(temp);if (list.find(temp) != list.end()) {(*(list.find(temp))).second = false;}}for (ll = list.begin(); ll != list.end(); ll++) {if ((*ll).second == true) {counter++;}}cout << counter << endl;}return 0;}

走马观花之外,这才是深入体验,探索自我的最佳时间,

Sicily 1938. Message Flood

相关文章:

你感兴趣的文章:

标签云: