解题报告

题意:

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

思路:

字典树爆。

#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. java基础58 JavaScript的几种格式和变量的声明方式(网页知识)

    1.JavaScript的几种格式 1.1.JavaScript的特点 1.跨平台性    2.安全性.(javaScript代码不能直接访问电脑硬盘上的信息) 1.2.Java与javaScript ...

  2. IE手工导入证书

    打开cer文件->欢迎使用证书导入向导->下一步->将所有的证书放入下列存储->受信任的根证书颁发机构->完成

  3. php内存管理机制与垃圾回收机制

    PHP内存管理机制 1 var_dump(memory_get_usage()); //获取内存 2 $a = "laruence"; //定义一个变量 3 var_dump(me ...

  4. 浮动元素垂直居中,bootstrap栅格布局垂直居中

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. AdvStringGrid 标题头

    标题头内容: 字体: 标题头高度: 头的对齐方式:

  6. POJ 3376 Finding Palindromes(manacher求前后缀回文串+trie)

    题目链接:http://poj.org/problem?id=3376 题目大意:给你n个字符串,这n个字符串可以两两组合形成n*n个字符串,求这些字符串中有几个是回文串. 解题思路:思路参考了这里: ...

  7. 使用mui框架打开页面的几种不同方式

    1.创建子页面: list.html就是index.html的子页面,创建代码比较简单,如下: mui.init({ subpages: [{ url: 'list.html', //子页面HTML地 ...

  8. 20155309 《Java程序设计》实验三(Java面向对象程序设计)实验报告

    一.实验内容及步骤 (一)编码标准 在IDEA中使用工具(Code->Reformate Code)把代码重新格式化. (二)在码云上把自己的学习搭档加入自己的项目中,确认搭档的项目加入自己后, ...

  9. SQL 2008 还原SQL 2005备份文件不成功的解决方

    在SQL Server 2008 r2上还原一个SQL Server 2005时,还原不成功,提示如下信息: 按照如下情况则还原成功: -- 查看备份文件的类型 RESTORE FILELISTONL ...

  10. 一步一步学习IdentityServer3 (9)

    idr添加验证码,授权方法中获取不到session,而且没有login页面的post方法,只有一个视图,而且是先加载视图,生成不了验证码 我的解决方法是将验证写一个自定义mvc控件  利用 viewd ...