UVa409_Excuses, Excuses!(小白书字符串专题)
解题报告
题意:
找包括单词最多的串。有多个按顺序输出
思路:
字典树爆。
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std;
int k,e,num[100],cnt;
struct node
{
int v;
node *next[26];
};
node *newnode()
{
node *p=new node;
p->v=0;
int i;
for(i=0;i<26;i++)
p->next[i]=NULL;
return p;
}
void addnode(node *root,char *str)
{
int i,l=strlen(str);
node *p=root;
for(i=0;i<l;i++)
{
int t=str[i]-'a';
if(p->next[t]==NULL)
p->next[t]=newnode();
p=p->next[t];
}
p->v=1;
}
int findd(node *root,char *str)
{
node *p=root;
int i,l=strlen(str);
for(i=0;i<l;i++)
{
int t=str[i]-'a';
if(p->next[t]==NULL)
return 0;
p=p->next[t];
}
return p->v;
}
int main()
{
char ch[100],str[100][100];
int i,j,m,kk=1;
while(~scanf("%d%d",&k,&e))
{
node *root=newnode();
for(i=0;i<k;i++)
{
scanf("%s",ch);
addnode(root,ch);
}
getchar();
int maxx=0;
for(i=0;i<e;i++)
{
fgets(str[i],100,stdin);
int l=strlen(str[i]);
m=0;
cnt=0;
for(j=0;j<l;j++)
{
if((str[i][j]>='a'&&str[i][j]<='z')||(str[i][j]>='A'&&str[i][j]<='Z'))
{
if(str[i][j]>='A'&&str[i][j]<='Z')
ch[m++]=str[i][j]+32;
else ch[m++]=str[i][j];
}
else
{
ch[m]=0;
m=0;
if(findd(root,ch))
cnt++;
}
}
if(maxx<cnt)
maxx=cnt;
num[i]=cnt;
}
printf("Excuse Set #%d\n",kk++);
for(i=0;i<e;i++)
{
if(num[i]==maxx)
printf("%s",str[i]);
}
printf("\n");
}
return 0;
}
Excuses, Excuses! |
Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge
Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case.
Input
Input to your program will consist of multiple sets of data.
- Line 1 of each set will contain exactly two integers. The first number ( ) defines the number of keywords to be used in the
search. The second number ( ) defines the number of excuses in the set to be searched. - Lines 2 through K+1 each contain exactly one keyword.
- Lines K+2 through K+1+E each contain exactly one excuse.
- All keywords in the keyword list will contain only contiguous lower case alphabetic characters of length L ( ) and
will occupy columns 1 through L in the input line. - All excuses can contain any upper or lower case alphanumeric character, a space, or any of the following punctuation marks [
SPMamp
".,!?&] not including the square brackets and will not exceed 70 characters in length. - Excuses will contain at least 1 non-space character.
Output
For each input set, you are to print the worst excuse(s) from the list.
- The worst excuse(s) is/are defined as the excuse(s) which contains the largest number of incidences of keywords.
- If a keyword occurs more than once in an excuse, each occurrance is considered a separate incidence.
- A keyword ``occurs" in an excuse if and only if it exists in the string in contiguous form and is delimited by the beginning or end of the line or any non-alphabetic character or a space.
For each set of input, you are to print a single line with the number of the set immediately after the string ``Excuse Set #". (See the Sample Output). The following line(s) is/are to contain
the worst excuse(s) one per line exactly as read in. If there is more than one worst excuse, you may print them in any order.
After each set of output, you should print a blank line.
Sample Input
5 3
dog
ate
homework
canary
died
My dog ate my homework.
Can you believe my dog died after eating my canary... AND MY HOMEWORK?
This excuse is so good that it contain 0 keywords.
6 5
superhighway
crazy
thermonuclear
bedroom
war
building
I am having a superhighway built in my bedroom.
I am actually crazy.
1234567890.....,,,,,0987654321?????!!!!!!
There was a thermonuclear war!
I ate my dog, my canary, and my homework ... note outdated keywords?
Sample Output
Excuse Set #1
Can you believe my dog died after eating my canary... AND MY HOMEWORK? Excuse Set #2
I am having a superhighway built in my bedroom.
There was a thermonuclear war!
UVa409_Excuses, Excuses!(小白书字符串专题)的更多相关文章
- UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)
解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...
- UVa567_Risk(最短路)(小白书图论专题)
解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...
- UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...
- UVa563_Crimewave(网络流/最大流)(小白书图论专题)
解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...
- UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...
- LeetCode 字符串专题(一)
目录 LeetCode 字符串专题 <c++> \([5]\) Longest Palindromic Substring \([28]\) Implement strStr() [\(4 ...
- NOIP2018提高组金牌训练营——字符串专题
NOIP2018提高组金牌训练营——字符串专题 1154 回文串划分 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有多种划分方式. a|bb|aabaa - 3 个 ...
- UVA 571 Jugs ADD18 小白书10 数学Part1 专题
只能往一个方向倒,如c1=3,c2=5,a b从0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1- ...
随机推荐
- 再谈OPENCV(转)
转自:http://blog.csdn.net/carson2005/article/details/6979806 尽管之前写过一篇关于OpenCV的介绍(http://blog.csdn.net/ ...
- Ubuntu CEPH快速安装
一.CEPH简介 不管你是想为云平台提供Ceph 对象存储和/或 Ceph 块设备,还是想部署一个 Ceph 文件系统或者把 Ceph 作为他用,所有 Ceph 存储集群的部署都始于部署一个个 Cep ...
- 从exp入手分析漏洞
分析poc和分析exp有一些不一样,因为exp是人为构造后的东西,它会执行一段自定的shellcode.结果是根本不会触发异常或者异常在离触发点十万八千里的地方.这样分析poc的技巧就用不上了(因为无 ...
- **后台怎么处理JSON数据中含有双引号?
http://bbs.csdn.net/topics/390578406?page=1 注意是后台,不是用js另外我这个json是直接取得别人的传过来的字符串,不是我自己拼写的,所以我自己不能做到转义 ...
- 使用celery时要注意的任务调用形式
因为之前,一直用django和celery紧密集成,不分家. 所以使用时参考了网上的配置之后,没有变更过. 最近,和洪军想用k8s的pod重新规划系统构架时,这个问题才又浮了出来. 只是我们的task ...
- jsonrpc.js -- 原生js实现 JSON-RPC 协议
很早以前就涉及到多端远程调用 api的设计,那时候自己设计了个消息传递回调过程.最近了解了JSON-RPC协议,更正规,就可以自己实现下.逻辑也不复杂,没有限制底层消息传递的方式,可以应用到更多的场景 ...
- 《Android源码设计模式》--享元模式
No1: 享元模式是对象池的一种实现.享元模式用来尽可能减少内存使用量,它适合用于可能存在大量重复对象的场景,来缓存可共享的对象,达到对象共享.避免创建过多对象的效果,这样一来就可以提升性能.避免内存 ...
- Wannafly挑战赛9 A - 找一找
链接:https://www.nowcoder.com/acm/contest/71/A来源:牛客网 题目描述 给定n个正整数,请找出其中有多少个数x满足:在这n个数中存在数y=kx,其中k为大于1的 ...
- PHP接入支付宝支付
创建应用 使用支付宝账号登录开放平台创建应用,应用创建成功之后可以得到APPID等相关信息 接着需要设置RSA密钥,可以使用蚂蚁金服开放平台提供的生成工具,生成完密钥需在开放平台中填写. 代码接入 引 ...
- socket--多进程,多线程服务器
一:概念: 我们知道IP地址是标志网络中不用主机的IP地址,而端口号就是同一台主机上标志不同进程的地址,IP地址和端口号标志网络中的唯一地址.(又称socket) 在TCP协议中,建⽴立连接的两个进程 ...