HDU 2328 POJ 3450 KMP
题目链接: HDU http://acm.hdu.edu.cn/showproblem.php?pid=2328
POJhttp://poj.org/problem?id=3450
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int maxn=4444; char x[222],ans[222];
char f[maxn][222];
int next[222]; void strcpy(char *y,int i,int len){
for(int j=0;j<len;++i,++j)
x[j]=y[i];
x[len]='\0';
}
void Get_Next(char *s){
int len=strlen(s);
next[0]=-1;
int i=0, j=-1;
while(i<len){
if(j==-1||s[i]==s[j]){
if(s[++i]==s[++j])
next[i]=next[j];
else next[i]=j;
}
else j=next[j];
}
}
bool KMP(char *s,char *a){//cout<<1<<endl;
int ls=strlen(s), la=strlen(a);
Get_Next(a);
int i=0, j=0;
while(i<ls&&j<la){
if(j==-1||s[i]==a[j])
++i,++j;
else j=next[j];
}
if(j>=la) return true;
return false;
}
int main(){
int n;
while(~scanf("%d",&n),n){
for(int i=0;i<n;++i)
scanf("%s",f[i]);
int len=strlen(f[0]);
bool flag=false;
ans[0]='\0';
for(int i=len;i&&!flag;--i)
for(int j=0,k;j<=len-i;++j){
strcpy(f[0],j,i);
for(k=1;k<n;++k)
if(!KMP(f[k],x))break;
if(k==n)//cout<<x<<endl;
if(!flag||strcmp(ans,x)>0){
strcpy(ans,x); flag=true;
}
}
if(flag)
puts(ans);
else
puts("IDENTITY LOST");
}
return 0;
}
HDU 2328 POJ 3450 KMP的更多相关文章
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- 字符串截取模板 && POJ 3450、3080 ( 暴力枚举子串 && KMP匹配 )
//截取字符串 ch 的 st~en 这一段子串返回子串的首地址 //注意用完需要根据需要最后free()掉 char* substring(char* ch,int st,int en) { ; c ...
- HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)
Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...
- hdu 2844 poj 1742 Coins
hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...
- hdu 5510 Bazinga(字符串kmp)
Bazinga Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)
Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...
- HDU 2494/POJ 3930 Elevator(模拟)(2008 Asia Regional Beijing)
Description Too worrying about the house price bubble, poor Mike sold his house and rent an apartmen ...
- 扫描线三巨头 hdu1928&&hdu 1255 && hdu 1542 [POJ 1151]
学习链接:http://blog.csdn.net/lwt36/article/details/48908031 学习扫描线主要学习的是一种扫描的思想,后期可以求解很多问题. 扫描线求矩形周长并 hd ...
- hdu 1540/POJ 2892 Tunnel Warfare 【线段树区间合并】
Tunnel Warfare Time Limit: 4000/2000 MS ...
随机推荐
- 转:用JS判断IE浏览器的版本(-- 很巧妙实用的方法)
~~在看到这篇文章之前如果让我来判断IE的版本,那么我基本上会用 navigator.userAgent去做字符串检索,现在觉得特性检测的确比较靠谱一点 今天一个项目中需要判断IE版本号,又因为 jQ ...
- Log Collect
http://ossectools.blogspot.com/2011/03/comprehensive-log-collection.html https://www.hacking-lab.com ...
- An update on OS X Code Signing(OS X代码签名)
There has recently been updates to the OS X code signing process. These updates also affect Qt appli ...
- SpringBoot接口服务处理Whitelabel Error Page(转)
To switch it off you can set server.error.whitelabel.enabled=false http://stackoverflow.com/question ...
- Windows Azure 社区新闻综述(#77 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 · 文章: Windows Azure 表存储简 ...
- BZOJ 1614: [Usaco2007 Jan]Telephone Lines架设电话线
题目 1614: [Usaco2007 Jan]Telephone Lines架设电话线 Time Limit: 5 Sec Memory Limit: 64 MB Description Farm ...
- nginx日志每日定时写入Hdfs
#!/bin/bash hadoop_home=/opt/hadoop-2.4.0 tw_nginx_log_file=/home/chiline.com.all/access_com_tw.log ...
- 转化为用欧几里得算法判断互质的问题D - Wolf and Rabbit
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- cmake 学习笔记(一)
最大的Qt4程序群(KDE4)采用cmake作为构建系统 Qt4的python绑定(pyside)采用了cmake作为构建系统 开源的图像处理库 opencv 采用cmake 作为构建系统 ... 看 ...
- 11g的alert日志路径
一个测试库,11g,没有sys账户,无法用show parameter dump查看alert日志的路径,以前也碰到过,但后来就不了了之了.这次深挖下,也参考了下一些网上的帖子,于是找到了: $ORA ...