http://poj.org/problem?id=3450

直接暴力枚举第一行的每一个字串,在下面的字符串中查找就行了,注意不符合就及时break。

然后试了一下strstr,发现效率是KMP的3-4倍。

还可以先排序找出最短的字符串,然后暴力,但是sort好像不能对char的二维数组排序,只能用string,string的字符串处理的函数都还没怎么看,就懒得搞了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; char a[][];
int n; bool cmp(char *x,char *y)
{
return strlen(x) < strlen(y);
} int main()
{
while(scanf("%d",&n) && n)
{
for(int i = ;i <= n;i++) scanf("%s",a[i]);
int len = strlen(a[]);
char t[],ans[] = "";
for(int i = ;i < len;i++)
{
int cnt = ;
for(int j = i;j < len;j++)
{
t[cnt++] = a[][j];
t[cnt] = ;
int flag = ;
for(int k = ;k <= n;k++)
{
if(!strstr(a[k],t))
{
flag = ;
break;
}
}
if(flag)
{
if(strlen(t) > strlen(ans) || strlen(t) == strlen(ans) && strcmp(t,ans) < )
{
memcpy(ans,t,sizeof(t));
}
}
}
}
if(strlen(ans) == ) printf("IDENTITY LOST\n");
else puts(ans);
}
return ;
}

最新文章

  1. NodeJs+http+fs+request+cheerio 采集,保存数据,并在网页上展示(构建web服务器)
  2. Web Essentials之Markdown和自定义编辑器(Web Essentials完结)
  3. KMP的原理详细讲解
  4. activeMQ下载,安装,启动,关闭
  5. 后序/中序---&gt;前序
  6. 深入ThreadLocal之三(ThreadLocal可能引起的内存泄露)
  7. glibc strlen delphi pascal
  8. TP复习6
  9. jsp的&lt;%@ include file=&quot;jsp/common.jsp&quot; %&gt;报错误Duplicate local variable basePath
  10. bzoj2719[Violet 4]银河之星
  11. office文档转pdf
  12. iOS 如何优化 App 的启动时间
  13. 【C++】智能指针简单剖析
  14. centos7数据库连接使用127.0.0.1报permission denied,使用localhost报No such file or directory
  15. 使用PHP生成和获取XML格式数据
  16. sencha touch 入门系列 (五)sencha touch运行及代码解析(上)
  17. Linux必会必知
  18. HDU - 6444(单调队列+思维)
  19. ZOJ Monthly, January 2019 Little Sub and his Geometry Problem ZOJ4082(模拟 乱搞)
  20. jquery插件需要明白的那些知识点

热门文章

  1. 1033 旧键盘打字 (20 分)C语言
  2. 小小知识点(三十八)MPSK和MQAM调制的实现——利用IQ调制
  3. 【一起学源码-微服务】Ribbon 源码四:进一步探究Ribbon的IRule和IPing
  4. 微信小程序吸顶功能
  5. 在Windows Server 2003中搭建DNS服务器
  6. 全流程开发 TP6.0实战高并发电商服务系统*完
  7. Java Linked集合的简单介绍和常用方法的使用
  8. 第五篇:python购物车小程序开发demo
  9. 若依框架. 仿ThymeLeaf前端SelectDictLable方法
  10. 真机调试报The executable was signed with invalid entitlements.错误