POJ_3450_KMP
2024-10-08 06:57:38
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 ;
}
最新文章
- NodeJs+http+fs+request+cheerio 采集,保存数据,并在网页上展示(构建web服务器)
- Web Essentials之Markdown和自定义编辑器(Web Essentials完结)
- KMP的原理详细讲解
- activeMQ下载,安装,启动,关闭
- 后序/中序--->;前序
- 深入ThreadLocal之三(ThreadLocal可能引起的内存泄露)
- glibc strlen delphi pascal
- TP复习6
- jsp的<;%@ include file=";jsp/common.jsp"; %>;报错误Duplicate local variable basePath
- bzoj2719[Violet 4]银河之星
- office文档转pdf
- iOS 如何优化 App 的启动时间
- 【C++】智能指针简单剖析
- centos7数据库连接使用127.0.0.1报permission denied,使用localhost报No such file or directory
- 使用PHP生成和获取XML格式数据
- sencha touch 入门系列 (五)sencha touch运行及代码解析(上)
- Linux必会必知
- HDU - 6444(单调队列+思维)
- ZOJ Monthly, January 2019 Little Sub and his Geometry Problem ZOJ4082(模拟 乱搞)
- jquery插件需要明白的那些知识点
热门文章
- 1033 旧键盘打字 (20 分)C语言
- 小小知识点(三十八)MPSK和MQAM调制的实现——利用IQ调制
- 【一起学源码-微服务】Ribbon 源码四:进一步探究Ribbon的IRule和IPing
- 微信小程序吸顶功能
- 在Windows Server 2003中搭建DNS服务器
- 全流程开发 TP6.0实战高并发电商服务系统*完
- Java Linked集合的简单介绍和常用方法的使用
- 第五篇:python购物车小程序开发demo
- 若依框架. 仿ThymeLeaf前端SelectDictLable方法
- 真机调试报The executable was signed with invalid entitlements.错误