关闭

Message Flood

152人阅读 评论(0) 收藏 举报
分类:

题目描述

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<string>
#include<algorithm>
#include<memory.h>
using namespace std;
bool cmp(string a,string b)//字符串的比较;
{
    return a<b;//升序比较;
}
string name[20001],t;//string定义字符串变量;
bool found [20001];
int n,m;
bool bi_search()//二分法查找;
{
    int start=0,mid,end=n-1;
    while(start<=end)
    {
        mid=(start+end)/2;
        if(t==name[mid])
        {
            if(!found[mid])
            {


            found[mid]=true;//查找到;
            return true;
            }
        else
            return false;
        }
        else if(t<name[mid])//前端查找;
            end=mid-1;
        else//后端查找;
            start=mid+1;
    }
    return false;
}
int main()
{
    int i,count;//统计剩下的人名;
    while(cin>>n&&n)
    {
        cin>>m;
        memset(found,false,sizeof(found));
        //memset(found,false,20001*sizeof(bool);//初始化;
        for(i=0;i<n;i++)
        {
            cin>>name[i];
            for(int j=0;j<name[i].length();j++)
                if(name[i][j]>='A'&&name[i][j]<='Z')
                name[i][j]+=32;
               // name[i][j]=tolower(name[i][j]);//将大写字符变为小写字符;
        }
        count=n;
        sort(name,name+n,cmp);//按照字典序升序排列;
        for(i=0;i<m;i++)
        {
            cin>>t;
            for(int j=0;j<t.length();j++)
                t[j]=tolower(t[j]);//将大写字符变为小写字符;
            if(bi_search())
                count--;
        }
       cout<<count<<endl;
    }
}

0
0
查看评论

信息洪流(1004. Message Flood)

题目大意是,有多组测试数据,以0结束shu
  • u012421896
  • u012421896
  • 2014-11-01 21:08
  • 393

Message Flood sdutoj 1500 (STL map 的使用)

Message Flood Time Limit: 1500MS Memory Limit: 65536KB Problem Description Well, how do you feel about mobile phone? Your answer wou...
  • Gentle_Guan
  • Gentle_Guan
  • 2016-10-12 21:04
  • 376

南邮- Message Flood

Message Flood
  • u010951938
  • u010951938
  • 2014-01-16 14:57
  • 994

Message Flood

 trie tree 字典树 trie的原理是利用字符串集合中字符串的公共前缀来降低时间开销以达到提高效率的目的。它具有以下性质:1,根结点不包含任何字符信息;2,如果字符的种数为n,则每个结点的出度为n(这样必然会导致浪费很多空间,这也是trie的缺点,我还...
  • lyg105504
  • lyg105504
  • 2010-05-27 01:23
  • 1529

Message Flood

Message Flood Time Limit: 1500MS    Memory limit: 65536K 题目描述 Well, how do you feel about mobile phone? Your answer would proba...
  • u013488894
  • u013488894
  • 2014-02-18 11:01
  • 337

STL--D - Message Flood

D - Message Flood Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%lld & ...
  • u013015642
  • u013015642
  • 2014-08-04 21:45
  • 464

Message Flood《字典树》

Message Flood Time Limit: 1500ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Well, how do you feel about mobile phone? Your a...
  • yeguxin
  • yeguxin
  • 2014-08-25 21:20
  • 523

【1500】Message Flood (SDUTOJ)

Message Flood Time Limit: 1500ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Well, how do you feel about mobile p...
  • jiangyongy
  • jiangyongy
  • 2014-08-23 10:50
  • 291

Sicilly 1194 Message Flood

Description Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits p...
  • u013087645
  • u013087645
  • 2014-08-13 21:37
  • 360

Message Flood(STL)

Message FloodCrawling in process... Crawling failed Time Limit:1500MS     Memory Limit:65536KB     64bit IO Fo...
  • u013486414
  • u013486414
  • 2014-08-04 18:18
  • 397
    个人资料
    • 访问:85257次
    • 积分:3236
    • 等级:
    • 排名:第12490名
    • 原创:233篇
    • 转载:82篇
    • 译文:0篇
    • 评论:16条
    文章分类
    最新评论