#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
using namespace std;
int Next[];
string s[];
void getNext(string s)
{
int i,j;
i=;
j=-;
int len=s.length();
Next[]=-;
while(i<len && j<len)
{
if(j==- || s[i]==s[j]) Next[++i]=++j;
else j=Next[j];
}
}
bool kmp(string m,string s)
{
getNext(s);
int i,j;
i=j=;
int mlen=m.length();// i
int slen=s.length();// j
while(i<mlen && j<slen)
{
if(j==- || m[i]==s[j]) i++,j++;
else j=Next[j];
}
if(j==slen) return false;
return true;
}
int main()
{
cin.sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string ms;
int mlen;
int flag=;
for(int i=;i<=n;i++)
{
cin>>s[i];
if(i==)
{
mlen=s[i].length();
ms=s[i];
}
else
{
int len=s[i].length();
if(len > mlen)
{
mlen=len;
ms=s[i];
}
}
}
flag=;
for(int i=;i<=n;i++)
{
//string now=q.front();
//q.pop();
string now=s[i];
int len=now.length();
if(len==mlen && now != ms)
{
flag=;
break;
}
//mq.push(now);
}
if(flag==) cout<<"No"<<endl;
else
{
int zflag=;
for(int i=;i<=n;i++)
{
string now=s[i];
if(kmp(ms,now))
{
zflag=;
break;
}
}
if(zflag==) cout<<"No"<<endl;
else cout<<ms<<endl;
}
}
return ;
}
// 补一发 kmp记录字串个数的

hdu 6208 上一个kmp模板的更多相关文章

  1. HDU 1711 - Number Sequence - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  2. HDU 1711Number Sequence【KMP模板题】

    <题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...

  3. HDU 1711 Number Sequence(KMP模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 这道题就是一个KMP模板. #include<iostream> #include<cs ...

  4. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

  5. hdu 1711 Number Sequence(KMP模板题)

    我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...

  6. HDU 6208 The Dominator of Strings【AC自动机/kmp/Sunday算法】

    Problem Description Here you have a set of strings. A dominator is a string of the set dominating al ...

  7. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  8. hdu 1358 Period(kmp求一个串的重复子串)

    题意:统计单串中从某个位置以前有多少重复的串 思路:kmp模板 #include<iostream> #include<stdio.h> #include<string. ...

  9. 2019/4/22 kmp模板

    题目连接:传送门!!! 这里是从头到尾彻底理解KMP的一篇博客,写的非常好 :https://blog.csdn.net/v_JULY_v/article/details/7041827 题意:输入多 ...

随机推荐

  1. Send me - PLANETSHAKERS

      Send me i will go 送我,我会去 send me i will go 送我,我会 to this city, to this nations 为这城市 为这国家 and to th ...

  2. H5内嵌原生app

    前言 其实我们不管是从ios还是安卓都可以看出 原生app能内嵌H5的原因是因为有了webview这个app内嵌浏览器视图,从而使得我们可以开发html然后加载到app中(原理几乎跟pc端请求.加载. ...

  3. JS-数组与伪数组

    数组与伪数组 把符合以下条件的对象称为伪数组: 具有length属性 按索引方式存储数据 不具有数组的push,pop等方法 伪数组(类数组):无法直接调用数组方法或期望length属性有什么特殊的行 ...

  4. ctl +→ = MAC 触控板三指手势

    我只想发一个这个:一直用外接显示器,但是不舍得抛弃全屏程序的切换,即:触控板三指手势. 期间各种百度无果,最多找到出最多的是触发角: 今天终于发现了:ctl +→  =  MAC 触控板三指手势 (外 ...

  5. Hibernate 自动更新表出错 建表或添加列,提示标识符无效

    如Oracle 数据库下报错: create table db_meta_web.user (id varchar2(255 char) not null, account varchar2(255 ...

  6. 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_04-用户认证技术方案-SpringSecurityOauth2

    2.3 Spring security Oauth2认证解决方案 本项目采用 Spring security + Oauth2完成用户认证及用户授权,Spring security 是一个强大的和高度 ...

  7. 算法习题---4-5IP网络(Uva1590)

    一:题目 给出m(1到10000之间)个IP地址,求他们最小的网络号和子网掩码 (一)样例输入 3 表示要获取的IP地址个数 194.85.160.177 IP地址 194.85.160.183 19 ...

  8. trylock方法

    synchronized 是不占用到手不罢休的,会一直试图占用下去. 与 synchronized 的钻牛角尖不一样,Lock接口还提供了一个trylock方法.trylock会在指定时间范围内试图占 ...

  9. 123456---com.twoapp.xiaoxiaofeixingyuan---小小飞行员

    com.twoapp.xiaoxiaofeixingyuan---小小飞行员

  10. plupload上传大文件

    大容量文件上传早已不是什么新鲜问题,在.net 2.0时代,HTML5也还没有问世,要实现这样的功能,要么是改web.config,要么是用flash,要么是用一些第三方控件,然而这些解决问题的方法要 ...