Message Flood(set)

Message Flood

Time Limit: 1500MS Memory limit: 65536K

题目描述

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.

输入

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.

输出

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

示例输入

5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0

示例输出

3

【转】
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
using namespace std;

int main()
{
    string str;
    int m,n;
    while(cin>>n && n)
    {
        set<string> myset;
        cin>>m;
        for(int i=0;i<n;i++)
        {
            cin>>str;
            for(int j=0;j<str.length();j++)//转换成小写,坑啊
                str[j]=tolower(str[j]);
            myset.insert(str);
        }
        for(int i=0;i<m;i++)
        {
            cin>>str;
            for(int j=0;j<str.length();j++)
                str[j]=tolower(str[j]);
            set<string>::iterator itor=myset.find(str);
            if(itor!=myset.end())
                myset.erase(str);
        }
        cout<<myset.size()<<endl;
    }
    return 0;
}
时间: 2024-10-12 21:54:33

Message Flood(set)的相关文章

NOJ 1121 Message Flood (Trie树 或者 map)

Message Flood 时间限制(普通/Java):2000MS/6000MS         运行内存限制:65536KByte 总提交:399          测试通过:105 题目描述 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". Howeve

STL 之map解决 Message Flood(原字典树问题)

Message Flood Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu 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".

Sicily 1194. Message Flood

题目地址: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;

sicily 1194 Message Flood (STL的map和set应用练习)

题目: D - Message Flood Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu 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

Message Flood --set相关操作

Message Flood Time Limit: 1500ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 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

NOJ1121 Message Flood STL应用

题意 一共认识n个人,过节了,要给每个人都发一个短信.不过已经收到了m条短信,如果收到了某个认识的人的短信就不用再给他发短信了.最后要发多少短信呢? 思路 用STL的map能够简化问题.注意字符串不区分大小,所以用transform方法来把string全部大写化. 代码 #include <cstdio> #include <cstring> #include <map> #include <algorithm> #include <string>

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

(转)sicily题目分类

Sicily题目分类 ·         [数据结构/图论] 1310 Right-Heavy Tree   笛卡尔树相关,复杂度O(N)或O(NlogN). ·1426 Phone List         电话号码前缀检索,trie树相关. ·1443 Printer Queue      基本队列操作. ·1149 等价表达式         判断表达式是否等价(递归求解) ·1136 山海经             n长序列里求m次区间询问的最大连续子区间和.线段树/RMQ ·1252

基于openfire+smack即时通讯instant message开发

前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire 是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使用3.8.1版本,这个版本是当前最新的版本,而且网上可以找到下载的源代码. 即时通信客户端可使用spark2.6.3,这个版本是目前最新的release版本,经过测试发现上一版本在视频支持,msn网关支持上可能有问题,所以选择openfire3.8.1+spark2.6.3是最合适的选择. Smac