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 ...
随机推荐
- networkcommon v3开源消息框架资料
http://www.cnblogs.com/csdev/category/870400.html
- mysql的binlog安全删除
理论上,应该在配置文件/etc/my.cnf中加上binlog过期时间的配置项,expire_logs_days = 10 但是如果没有加这一项,随着产生越来越多的binlog,磁盘被吃掉了不少.可以 ...
- PostgreSQL/bin
pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...
- 如何在RedHat6(7) or CentOS6(7)上制作无依赖的PostgreSQL数据库的RPM包
本文解决了源代码安装都需要先检查系统上是否安装了应用程序所依赖的软件包的烦恼,对源代码开发者也有一定的帮助.可以在该基础上进行适当的修改,以满足自己的要求. RedHat5 or CentOS5已经提 ...
- Sublime 不自动打开上次未关闭的文件 设置方法
{ "font_size": 17, "hot_exit": false, "remember_open_files": false, &q ...
- Java基础(36):String与基本数据类型之间的双向转换(Wrapper类)
Java 中基本类型和字符串之间的转换 在程序开发中,我们经常需要在基本数据类型和字符串之间进行转换. 其中,基本类型转换为字符串有三种方法: 1. 使用包装类的 toString() 方法 2. 使 ...
- 关于内存 GetMemory( ) 笔试分析
1. #include<stdio.h>#include<string.h>void GetMemory(char *p){ p=(char *)malloc(100); }i ...
- 夺命雷公狗---node.js---16之项目的构建在node+express+mongo的博客项目1
废话不多说我们直接开工... 直接在目录下打开黑窗口: 然后就开始看看我们创建出来的文件了: 然后就开始创建项目下的目录了: 从这里就可以清晰的看得到我们的目录都是以前后台来分离开来的,引入模版也很简 ...
- linux的vim按了ctrl+s之后假死的解决办法
习惯了很多软件的保存的快捷键,经常在vim中按下ctrl+s,然后就发现vim不响应了,之间一直采用kill的方式解决,近来搜了一下,是这样子的: 这时的vim并没有死掉,只是vim不再向终端输出东西 ...
- 通过进程检测服务时脚本文件名不要起要检测的服务名字命名 shell程序从上到下执行若定义函数或引用系统函数需先定义 kill -USR2
通过进程检测服务时脚本文件名不要起要检测的服务名字命名 kill -USR2 `cat /var/run/mysqld.pid`