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 ...
随机推荐
- transient关键字的含义
transient java语言的关键字,变量修饰符,如果用transient声明一个实例变量,当对象存储时,它的值不需要维持. Java的serialization提供了一种持久化对象实例的机制.当 ...
- 为benchmarksql的PostgreSQL java驱动进行升级
为benchmarksql的PostgreSQL java驱动进行升级[root@minion1 benchmarksql-4.1.0]# wget https://jdbc.postgresql.o ...
- php-引号中出现$
当双引号中包含变量时,变量对应的值会与双引号中的内容连接在一起: 当单引号中包含变量时,变量会被当做字符串输出. 慕课网,I love you!慕课网,$love
- 关于vptr指针初始化的分步
vptr:一个具有虚函数类的对象所具有的隐藏的成员,指向该类的虚函数表. 父类对象的vptr指向是一直指向父类的.但子类的vptr指针最终是指向子类的, 当子类创建的时候,先调用父类构造函数,这个时候 ...
- JSon_零基础_006_将JSon格式的字符串转换为Java对象
需求: 将JSon格式的字符串转换为Java对象. 应用此技术从一个json对象字符串格式中得到一个java对应的对象. JSONObject是一个“name.values”集合, 通过get(key ...
- CSS_03_04_CSS伪元素选择器
第01步:编写css代码:wei.css @charset "utf-8"; /* 伪元素选择器 :状态 效果顺序:L V H A */ a:link.lin_01{/*超链接,未 ...
- angular 依赖注入
依赖注入 依赖注入(DI)是一个经典的设计模式, 主要是用来处理组件如何获得依赖的问题.关于DI,推荐阅读Martin Flower的文章(http://martinfowler.com/art ...
- 夺命雷公狗---Thinkphp----15之遍历出来的栏目页的完成
我们首页的写法和我们的文章页的代码很相似,我们要在点击我们的栏目页的时候遍历出对应的代码: 那么我们就直接来创建一个ListsController.class.php的文件,代码如下所示: 老规矩遍历 ...
- 3. 星际争霸之php设计模式--简单工厂模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- form 表单jquery验证插件使用
第一部分:表单样式 <form action="#" method="post" id="regist"> <tabl ...