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
 1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 void strUpr( char *str )//转换小写为大写的函数,本题目这是关键点
5 {
6 int i, len = strlen(str);
7
8 for ( i = 0; i < len; i++ )
9 {
10 if( str[i] <= 'z' && str[i] >= 'a' )
11 str[i] = str[i] - 'a' + 'A';
12 }
13 }
14 void sort(char a[][20],int l,int r)
15 {
16 char x[20];
17 strcpy(x,a[l]);
18 int i=l,j=r;
19 if(l>=r)return ;
20 while(i<j)
21 {
22 while(i<j&&strcmp(a[j],x)>=0)j--;
23 strcpy(a[i],a[j]);
24 while(i<j&&strcmp(a[i],x)<=0)i++;
25 strcpy(a[j],a[i]);
26 }
27 strcpy(a[i],x);
28 sort(a,l,i-1);
29 sort(a,i+1,r);
30 }
31 int binsearch(char a[][20],int s,int t,char key[])
32 {
33 int low=s,high=t,mid;
34 if(s<=t)
35 {
36 mid=low+(high-low)/2;
37 if(strcmp(a[mid],key)==0)
38 return mid;
39 if(strcmp(a[mid],key)>0)
40 return binsearch(a,low,mid-1,key);
41 else
42 return binsearch(a,mid+1,high,key);
43 }
44 return -1;
45 }
46 int main()
47 {
48 int m;
49 while(scanf("%d",&m)&&m!=0)
50 {
51 char f[20001][20],g[20001][20];
52 if(m==0)break;
53 else
54 {
55 int sum=0;//sum1为了标记重复元素的个数
56 int n;
57 scanf("%d",&n);
58 int i;
59 for(i=0;i<=m-1;i++)
60 {
61 scanf("%s",f[i]);
62 strUpr(f[i]);
63 }
64 for(i=0;i<=n-1;i++)
65 {
66 scanf("%s",g[i]);
67 strUpr(g[i]);
68 }
69 sort(g,0,n-1);//快速排序
70 for(i=0;i<=m-2;i++)
71 {
72 if(strcmp(f[i],f[i+1])!=0)//相邻元素不相同,去重操作
73 {
74 if(binsearch(g,0,n-1,f[i])!=-1)//找到
75 sum=sum+1;
76 }
77 //else continue;//相邻元素相同的话,不操作,进入下一次循环
78 }
79 //补上最后一个元素的特判
80 if(binsearch(g,0,n-1,f[i])!=-1)//找到了的话
81 sum=sum+1;
82 printf("%d\n",m-sum);
83 }
84 }
85 return 0;
86 }

Message Flood的更多相关文章

  1. Sicily 1194. Message Flood

    题目地址:1194. Message Flood 思路: 不区分大小写,先全部转化为小写,用stl提供的函数做会很方便. 具体代码如下: #include <iostream> #incl ...

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

                                                                                      Message Flood Time ...

  3. SDUT1500 Message Flood

    以前做过的用的字典树,可是貌似现在再用超内存....求解释... 问了LYN用的map函数做的,又去小小的学了map函数.... http://wenku.baidu.com/view/0b08cec ...

  4. sdut Message Flood(c++ map)

    用字典树没过,学习了一下map; 参考博客:http://blog.csdn.net/zhengnanlee/article/details/8962432 AC代码 #include<iost ...

  5. Message Flood(map)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/D 以前用字典树做过 #include <strin ...

  6. oj1500(Message Flood)字典树

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

  7. SDUT 1500-Message Flood(set)

    Message Flood Time Limit: 1500ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 Well, how do you feel abo ...

  8. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  9. 浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)

    一.SOCK_RAW 内幕 首先在讲SOCK_RAW 之前,先来看创建socket 的函数: int socket(int domain, int type, int protocol); domai ...

随机推荐

  1. 4.1---二叉树是否平衡(CC150)

    //也就是把高度在递归过程中给一并算了.public class Balance { public static boolean checkBalance(TreeNode root, int[] d ...

  2. mysql 表关联查询报错 ERROR 1267 (HY000)

    解决翻案:http://stackoverflow.com/questions/1008287/illegal-mix-of-collations-mysql-error 即: SET collati ...

  3. Docker个人学习总结

    最近一段时间学习了下Docker,关于Docker的安装,运用什么的在这里我不会过多的说明,我只说我对于Docker的一些理解,附加我用于记录的少量代码. 刚开始学习Docker的时候,找资料在网上看 ...

  4. C# 接口基础

     接口只包含方法.属性.事件或索引器的签名. 实现接口的类或结构必须实现接口定义中指定的接口成员 接口中可以包含字段吗? 第一次被问到这个问题的时候被问愣住了,只能回答:印象当中没见过在接口中定义变量 ...

  5. mybaits in

    mybatis中的in: <select id="getByInventoryIds" resultMap="beanMap"> SELECT * ...

  6. Spring AOP基于配置文件的面向方法的切面

    Spring AOP基于配置文件的面向方法的切面 Spring AOP根据执行的时间点可以分为around.before和after几种方式. around为方法前后均执行 before为方法前执行 ...

  7. android studio插件提升工作效率

    SonarLint 代码质量管理插件 ButterKnife Zelezny ButterKnife 生成器,快速根据布局文件生成属性对象. SelectorChapek 设计师给我们提供好了各种资源 ...

  8. 解读Unity中的CG编写Shader系列一

    转自http://www.itnose.net/detail/6095323.html 前提知识点: 1.CG代码必须用 CGPROGRAM ... ENDCG括起来 2.顶点着色器与片段着色器的主函 ...

  9. switch/ifelse 使用总结

    2015年3月30日 14:12:36 switch 中的 default  和 if/else  中最后的 else 尽可能的不要用 1. 不要default, 不要写默认处理逻辑, default ...

  10. 调试WebService

    1.运行WebService的调用程序 2.浏览器中运行asmx,这一步是为了让w3wp.exe出现在下一步的列表中 3.“工具”或“调试”菜单-->附加到进程 (MS为什么把同一功能放在不同的 ...