Message Flood

来源:互联网 发布:win7打开23端口 编辑:程序博客网 时间:2024/06/07 07:16

Think:
没怎么看题意, 看输入输出 感觉就是 输入 几个名字, 然后 再输入 m个名字 计算 没出现名字的 个数;
思路:
用 SET《string》 来存储, 第二次输入时 判断人名是否出现, 出现过的话 计数器 +1 &&同时 消去人名。
坑点:
贼坑!!WA了好多发, 不区分大小写!!!! 所以 就要 全部转为大写或者 全部转为小写~~~~;
tolower()的 作用就是将小写字母 转换为大写字母。
toupper()的 作用就是将大写字母 转换为小写字母。

Problem 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 message 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 message, 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. 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. The input is terminated by n=0.
Output
For each case, print one integer in one line which indicates the number of left friends he must send.
Example Input

5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0

Example Output

3

#include<bits/stdc++.h>using namespace std;int main(){    int i;    set<string>s;    string key;    int n, m, j;    while(cin >> n)    {        if (n == 0)            return 0;        cin >> m;        int cnt = 0;        s.clear();        for (i = 0; i < n; i ++)        {            cin >> key;            for (j = 0;j < key.size();j ++)              {                key[j] = tolower(key[j]);              }            s.insert(key);        }        while(m --)        {            cin >> key;            for (j = 0;j < key.size();j ++)              {                key[j] = tolower(key[j]);              }            if (s.count(key) != 0)            {                cnt = cnt + 1;                s.erase(key);            }        }        cout << n - cnt << endl;    }}
原创粉丝点击