题目描述

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;
    }
}

Message Flood相关推荐

  1. sdut 1500 Message Flood

    一道简单的Trie树,好长时间没写过了,手生了,wA了好几次... Message Flood Time Limit:1500MS  Memory Limit:65536K Total Submit: ...

  2. 1194 . Message Flood

    Well, how do you feel about mobile phone? Your answer would probably be something like that "It ...

  3. oj1500(Message Flood)字典树

    大意:输入几个字符串,然后再输入几个字符串,看第一次输入的字符串有多少没有在后面的字符串中出现(后输入的字符串不一定出现在之前的字符串中) #include <stdio.h> #incl ...

  4. sdut 1500 Message Flood(Trie树)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1500 View Code 1 #incl ...

  5. Soj题目分类 python代码)

    正值期末复习,刷点soj放松下 但想看看能不能在找点关于数据结构的题目来做一下. 在网上看到有不少人上传过那些关于部分SOJ题目的描述,但是说实话有些乱 不过我看到有个网页中包含的一个类似文档的东西, ...

  6. 网络入侵检测系统之Suricata(七)--DDOS流量检测模型

    Suricata支持DDOS流量检测模型 What 分布式拒绝服务(Distributed Denial of Service,简称DDoS)将多台计算机联合起来作为攻击平台,通过远程连接利用恶意程序 ...

  7. 博客推荐|使用自定义指标在 Kubernetes 中自动扩展 Pulsar Functions

    本文翻译自 StreamNative 博客<Auto-Scaling Pulsar Functions in Kubernetes Using Custom Metrics>,作者付睿.吕 ...

  8. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

  9. sicily题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

最新文章

  1. 如何认识TOS----DSCP 对照表
  2. CENTOS MINI版安装tomcat9.0
  3. php 双向加密解密,一个php双向加密解密法
  4. 高 star 开源项目来实验楼啦,深度学习强推教材
  5. 肽键肽链内部分的计算机术语大全,生化资料
  6. ASP.NET Core 源码学习之 Options[3]:IOptionsSnapshot
  7. 质量审查一体化智能平台 搭建总览图
  8. virtualbox手动挂载共享文件夹
  9. ROS学习笔记2(ROS文件系统和ROS常用命令)
  10. 10.java之父被B站学习者下载达7000万次的Java视频教程你还没有看过知乎
  11. java 日语文档翻译_日语文档怎么翻译?我来教会你日语翻译
  12. 制造业数字化转型的意义是什么?
  13. Unity学习资源(超全)汇总 基础+项目+进阶+面试
  14. ios 简书 获取通讯录信息_ios 各种权限整理
  15. 注册最便宜的xyz域名,低成本搭建一个博客
  16. 餐饮app开发市场前景如何?行业竞争激烈吗?
  17. 【python--程序】printf格式化输出函数
  18. 【存档】中华成语千句文
  19. java人品计算器,‎App Store 上的“围棋死活大全”
  20. [转载]简介使用Java编写Palm OS程序的解决方案(2)

热门文章

  1. Linux系统常用的基本命令【转载CSDN象在舞】
  2. c语言死循环中输入字符,如下代码,如果输入字符,为什么会造成死循环?
  3. 前端面试技巧和注意事项_前端面试百分之九十九过的技巧
  4. hp打印机怎么连接电脑_打印机怎么连接电脑?安装打印机图文教程
  5. ios 图片居中裁剪_[ iOS Shortcuts / Workflow ] 分享一个给照片批量加「底部居中偏上」水印的捷径,可适应不同水印的尺寸...
  6. 【LeetCode笔记 - 每日一题】375. 猜数字游戏 II (Java、DFS、动态规划)
  7. 【LeetCode笔记】621. 任务调度器(Java、桶)
  8. java truevfs_Java-Apache Commons VFS:使用FTP
  9. java boolean 多线程_JAVA多线程两个实用的辅助类(CountDownLatch和AtomicBoolean)
  10. mysql导入greenplum_greenPlum中通过gpfdist导入文本数据到数据库表中