解题报告

题意:

找包括单词最多的串。有多个按顺序输出

思路:

字典树爆。

#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!(小白书字符串专题)的更多相关文章

  1. UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)

    解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...

  2. UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

    解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...

  3. UVa567_Risk(最短路)(小白书图论专题)

    解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...

  4. UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)

    解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...

  5. UVa563_Crimewave(网络流/最大流)(小白书图论专题)

    解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...

  6. UVa10397_Connect the Campus(最小生成树)(小白书图论专题)

    解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...

  7. LeetCode 字符串专题(一)

    目录 LeetCode 字符串专题 <c++> \([5]\) Longest Palindromic Substring \([28]\) Implement strStr() [\(4 ...

  8. NOIP2018提高组金牌训练营——字符串专题

    NOIP2018提高组金牌训练营——字符串专题 1154 回文串划分 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有多种划分方式.   a|bb|aabaa - 3 个 ...

  9. 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- ...

随机推荐

  1. 本地为Windows,使用Xshell登录Linux云主机

    以某东的云主机为实例 1. 下载并安装远程登录软件 下载Xshell软件 下载后双击xshell5_5.0.1332.exe进行安装 2. 安装完成,打开Xshell,并点击新建,根据要求输入相应参数 ...

  2. TypeScript的配置文件 tsconfig.json

    //tsconfig.json指定了用来编译这个项目的根文件和编译选项 { "compilerOptions": { //compilerOptions:编译选项,可以被忽略,这时 ...

  3. JS Ajax异步请求发送列表数据后面多了[]

    还在苦逼的写代码,这里就不详细了,直接抛出问题: 如图所示: 前端ajax请求向后端发送数据的时候,给key添加了[]出现很多找不到原因, 后面在说 解决方法: 暂时先这样记录一下,下次方便查找,好了 ...

  4. for循环练习--杨辉三角

    package org.hanqi.zwxx; public class Yonghuisanjiao{ public static void main(String[] args) { // TOD ...

  5. Caffe训练AlexNet网络模型——问题一

    训练AlexNet网络时,出现Check failed:datum_height >= crop_size (size vs. 227)错误,具体如下图所示: 根据提示,问题是crop_size ...

  6. 伪分布式安装Hadoop

    Hadoop简单介绍 Hadoop:适合大数据分布式存储与计算的平台. Hadoop两大核心项目: 1.HDFS:Hadoop分布式文件系统 HDFS的架构: 主从结构: 主节点,只有一个:namen ...

  7. thinkphp3.2中开启静态缓存后对404页面的处理方法

    静态缓存很实用但是有时有些不需要静态缓存,如404页面,第一次访问返回404页面并缓存,第二次换回的状态就是200,属于正常访问,虽然人眼可以看出是404页面,但是搜索引擎不会的,而是把这个页面当成正 ...

  8. 用 React 编写移动应用 React Native

    转载:用 React 编写移动应用 React Native ReactNative 可以基于目前大热的开源JavaScript库React.js来开发iOS和Android原生App.而且React ...

  9. iOS 9应用开发教程之使用代码添加按钮美化按钮

    iOS 9应用开发教程之使用代码添加按钮美化按钮 丰富的用户界面 在iOS9中提供了很多的控件以及视图来丰富用户界面,对于这些视图以及控件我们在上一章中做了简单的介绍.本章我们将详细讲解这些视图. i ...

  10. android 数据存储方式

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 1,文件 2,内容提供者 3,偏好设置 4,数据库 5,网络存储. 网络存储,就是上传到 ...