MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏
MessageFlood
TimeLimit: 1500ms Memory limit: 65536K
有疑问?点这里^_^
题目描述
Well,how do you feel about mobile phone? Your answer would probably besomething like that "It's so convenient
and benefits people alot". However, If you ask Merlin this question on the New Year'sEve, he will definitely answer "What a trouble! I have to keepmy fingers moving on the phone the whole night, because I have somany greeting message to send!" Yes, Merlin
has such a long namelist of his friends, and he would like to send a greeting message toeach of them. What's worse, Merlin has another long name list ofsenders that have sent message to him, and he doesn't want to sendanother message to bother them Merlin
is so polite that he alwaysreplies each message he receives immediately). So, before he beginsto send message, he needs to figure to how many friends are left tobe sent. Please write a program to help him. Here is something thatyou should note. First, Merlin's
friend list is not ordered, and eachname is alphabetic strings and case insensitive. These names areguaranteed to be not duplicated. Second, some senders may send morethan one message to Merlin, therefore the sender list may beduplicated. Third, Merlin is
known by so many people, that's why somemessage senders are even not included in his friend list.
输入
Thereare multiple test cases. In each case, at the first line there aretwo numbers n and m (1<=n,m<=20000),
which is the number offriends and the number of messages he has received. And then thereare n lines of alphabetic strings(the length of each will be lessthan 10), indicating the names of Merlin's friends, one per line.After that there are m lines of alphabetic
strings, which are thenames of message senders. The input is terminated by n=0.
输出
Foreach case, print one integer in one line which indicates the numberof left friends he must send.
示例输入
53
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0
示例输出
3
/*
用的字典树,<span style="font-family:华文楷体, serif;">因为发送有重复的,所以以发送的建树,总的进行查询</span>
*/:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <time.h>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <string>
#include <iostream>
#include <algorithm>
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
#define INF 0x3f3f3f3f using namespace std; const int Max=20100; struct node
{
bool flag;
node *next[26];
};
node * Creat()
{
node *p;
p=new node;
p->flag=false;
for(int i=0;i<26;i++)
{
p->next[i]=NULL;
}
return p;
}
void Build(char *s,node *head)
{
node *p;
p=head;
int a;
for(int i=0;s[i];i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
a=s[i]+32-'a';
}
else
{
a=s[i]-'a';
}
if(p->next[a]==NULL)
{
p->next[a]=Creat();
}
p=p->next[a];
}
p->flag=true;
}
bool Rcher(char *s,node *head)
{
node *p;
p=head;
int a;
for(int i=0;s[i];i++)
{
if(s[i]>='A'&&s[i]<='Z')
{
a=s[i]+32-'a';
}
else
{
a=s[i]-'a';
}
if(p->next[a]==NULL)
{
return false;
}
p=p->next[a];
}
return p->flag;
}
int main()
{
int n,m;
char s[Max][11];
char c[11];
while(scanf("%d",&n),n)
{
scanf("%d",&m);
node *head;
head=Creat();
for(int i=0;i<n;i++)
{
scanf("%s",s[i]);
}
for(int i=0;i<m;i++)
{
scanf("%s",c);
Build(c,head);
}
int ans=0;
for(int i=0;i<n;i++)
{
if(Rcher(s[i],head))
{
ans++; }
}
cout<<n-ans<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏的更多相关文章
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- django中url,静态文件,POST请求的配置 分类: Python 2015-06-01 17:00 789人阅读 评论(0) 收藏
平时使用的是pycharm,所以这篇文章主要也是使用pycharm默认创建的django项目为基础进行讲解.项目目录如下图: 1.URL的配置 当创建好项目后,运行项目就可以看到django默认的页面 ...
- strace使用详解(转) 分类: shell ubuntu 2014-11-27 17:48 134人阅读 评论(0) 收藏
(一) strace 命令 用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的 ...
- iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏
一.什么是正则表达式 正则表达式,又称正规表示法,是对字符串操作的一种逻辑公式.正则表达式可以检测给定的字符串是否符合我们定义的逻辑,也可以从字符串中获取我们想要的特定部分.它可以迅速地用极简单的方式 ...
- JAVA 关于Icon,Image,ImageIcon的简单的对比参考 分类: Java Game 2014-08-14 17:08 210人阅读 评论(0) 收藏
转自:http://blog.csdn.net/bcmissrain/article/details/7190886 其实就算是现在,我还是有不少地方概念模糊,但是下面的内容是是没有什么问题的.稍微介 ...
- 深入N皇后问题的两个最高效算法的详解 分类: C/C++ 2014-11-08 17:22 117人阅读 评论(0) 收藏
N皇后问题是一个经典的问题,在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行.同一列.同一斜线上的皇后都会自动攻击). 一. 求解N皇后问题是算法中回溯法应用的一个经典案例 回溯算 ...
- c++ 字符串流 sstream(常用于格式转换) 分类: C/C++ 2014-11-08 17:20 150人阅读 评论(0) 收藏
使用stringstream对象简化类型转换 C++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性.类型安全和可扩展性.在本文中 ...
- 合并k个已排序的链表 分类: leetcode 算法 2015-07-09 17:43 3人阅读 评论(0) 收藏
最先想到的是把两个linked lists 合并成一个. 这样从第一个开始一个一个吞并,直到所有list都被合并. class ListNode:# Definition for singly-lin ...
- IOS之按钮控件--Button全解析及使用 分类: ios技术 2015-01-17 17:09 169人阅读 评论(0) 收藏
IOS开发中伴随我们始终的 最常用的几个空间之一 -- UIButton 按钮,对于button今天在此做一些浅析,并介绍下主流用法以及常见问题解决办法. 首先是继承问题,UIButton继承于UIC ...
随机推荐
- Request、Servlet及其子接口
最近看tomcat源码,这类接口多的有点眩,整理出来看一下.(基于tomcat4) javax.servlet.ServletRequset接口,和org.apache.catalina.Reques ...
- 通用窗口类 Inventory Pro 2.1.2 Demo1(上)
插件功能 按照Demo1的实现,使用插件来实现一个装备窗口是很easy的,虽然效果还很原始但是也点到为止了,本篇涉及的功能用加粗标出,具体的功能如下: 1.实现了两个窗口,通过点击键盘I来,打开或者关 ...
- Iterator和ListIterator主要区别(转)
Iterator和ListIterator主要区别有: 一.ListIterator有add()方法,可以向List中添加对象,而Iterator不能. 二.ListIterator和Iterator ...
- Codeforce Round #227 Div2
这回的看错时间了! 发现理论可以涨分的- -
- FAQ: C++中定义类的对象:用new和不用new有何区别?
C++用new创建对象和不用new创建对象的区别解析 作者: 字体:[增加 减小] 类型:转载 时间:2013-07-26 我要评论 在C++用new创建对象和不用new创建对象是有区别的,不知你是否 ...
- VS2012离线安装Xamarin (含破解补丁)
Xamarin离线安装包 来源于 忘忧草 特此感谢! 离线安装不成功:参考源 http://www.cnblogs.com/zjoch/p/3937014.html / http://www.cnb ...
- C++之路进阶——bzoj1455(罗马游戏)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser gryz2016 Logout 捐赠本站 Notice:由于本OJ ...
- CSS_03_04_CSS伪元素选择器
第01步:编写css代码:wei.css @charset "utf-8"; /* 伪元素选择器 :状态 效果顺序:L V H A */ a:link.lin_01{/*超链接,未 ...
- [转]iis7.5+win2008 出现 HTTP Error 503. The service is unavailable.
解决: 应用程序池启动32位应用程序 设置托管管道为集成 (仍然有问题) 试试以下方法: http://phpwind.me/1222.html 楼主 发表于: 2011-11-26 图片: ...
- 关于nandflash与norflash
读取速度:nor > nand 写入速度:nand > nor 擦除速度:nand 4ms,nor 5s nand的擦除单元更小,相应的擦除电路更少. nand的实际应用方式比nor复杂, ...