Beside other services, ACM helps companies to clearly state their “corporate identity”, which includes company logo but also other signs, like trademarks. One of such companies is Internet Building Masters (IBM), which has recently asked ACM for a help with their new identity. IBM do not want to change their existing logos and trademarks completely, because their customers are used to the old ones. Therefore, ACM will only change existing trademarks instead of creating new ones.

After several other proposals, it was decided to take all existing
trademarks and find the longest common sequence of letters that is
contained in all of them. This sequence will be graphically emphasized
to form a new logo. Then, the old trademarks may still be used while
showing the new identity.

Your task is to find such a sequence.

InputThe input contains several tasks. Each task begins with a
line containing a positive integer N, the number of trademarks (2 ≤ N ≤
4000). The number is followed by N lines, each containing one trademark.
Trademarks will be composed only from lowercase letters, the length of
each trademark will be at least 1 and at most 200 characters.

After the last trademark, the next task begins. The last task is followed by a line containing zero.OutputFor each task, output a single line containing the longest
string contained as a substring in all trademarks. If there are several
strings of the same length, print the one that is lexicographically
smallest. If there is no such non-empty string, output the words
“IDENTITY LOST” instead.Sample Input

3
aabbaabb
abbababb
bbbbbabb
2
xyz
abc
0

Sample Output

abb
IDENTITY LOST 跟前面几道题都是类似的。枚举第一个串的所有后缀,然后和其余字符串匹配。得到的公共最小取最大。不断更新答案。
 #include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int n,Next[];
vector<string> t;
string s,ans; void prekmp(string s) {
int len=s.size();
int i,j;
j=Next[]=-;
i=;
while(i<len) {
while(j!=-&&s[i]!=s[j]) j=Next[j];
Next[++i]=++j;
}
} int kmp(string t,string p) {
int len=t.size();
int i,j,res=-;
i=j=;
while(i<len) {
while(j!=-&&t[i]!=p[j]) j=Next[j];
++i;++j;
res=max(res,j);
}
return res;
} int main() {
//freopen("in","r",stdin);
while(~scanf("%d",&n)&&n) {
for(int i=;i<n;i++) {
cin>>s;
t.push_back(s);
}
string str=t[],tempstr;
int maxx=-,res;
int len=str.size();
for(int i=;i<len;i++) {
tempstr=str.substr(i,len-i);
prekmp(tempstr);
res=;
for(int j=;j<t.size();j++) {
res=min(kmp(t[j],tempstr),res);
}
if(res>=maxx&&res) {
if(res==maxx) {
string tempstr1=tempstr.substr(,maxx);
if(tempstr1<ans)
ans=tempstr1;
} else {
maxx=res;
ans=tempstr.substr(,maxx);
}
}
}
if(ans.size()) cout<<ans<<endl;
else cout<<"IDENTITY LOST"<<endl;
ans.clear();
t.clear();
}
}

kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity的更多相关文章

  1. kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)

    Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...

  2. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  3. kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  4. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  5. kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  6. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo

    The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...

  8. kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence

    Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...

  9. kuangbin专题十六 KMP&&扩展KMP HDU3613 Best Reward(前缀和+manacher or ekmp)

    After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...

随机推荐

  1. Celery-4.1 用户指南: Workers Guide (Workers 指南)

    启动工作单元 你可以通过执行以下命令在前台启动工作单元: $ celery -A proj worker -l info 查看启动工作单元的可用命令行选项,可以执行: $ celery worker ...

  2. Python之函数目录(自定义函数,内置函数,装饰器,迭代器,生成器)

    1.初始函数 2.函数嵌套及作用域 3.装饰器 4.迭代器和生成器 6.内置函数 7.递归函数 8.匿名函数 9.函数相关定义 10.三元表达式.列表推导式.生成器表达式 11.函数与方法的区别  

  3. python jvm数据

    在网上找的抱歉忘了原链接了额 #!/usr/bin/env python # # import os import commands import re import sys (status1, re ...

  4. iOS多线程各种安全锁介绍 - 线程同步

    一.atomic介绍 github对应Demo:https://github.com/Master-fd/LockDemo 在iOS中,@property 新增属性时,可以增加atomic选项,ato ...

  5. LaTex: 表格单元格内容 分行显示/换行

    问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示 答:(来源于smth) 方案一: \newcommand{\tabincell}[2]{\begin{ta ...

  6. sql server导入excel等数据

    1.首先打开并登陆sql server数据库 2.选择要将表导入的数据库,右击选择任务-->导入数据 3.在弹出的窗口中选择下一步 4.在弹出的窗口中选择数据源,也就是从哪种文件导入,sql s ...

  7. 1、序列化 2、转义 3、eval 4、正则表达式 5、时间处理

    1.序列化 JSON.stringify(obj)   序列化 JSON.parse(str)        反序列化 2.转义 decodeURI( )                   URl中 ...

  8. android手势(gesture)

    需要实现两个接口,OnTouchListener ,OnGestureListener 在接口方法中实现各种事件 详见:http://www.cnblogs.com/JczmDeveloper/p/3 ...

  9. 一个典型的PHP分页实例代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 使用RSS提升DPDK应用的性能(转)

    本文描述了RSS以及在DPDK中如何配置RSS达到性能提升和统一分发. 什么是RSS RSS(Receive Side Scaling)是一种能够在多处理器系统下使接收报文在多个CPU之间高效分发的网 ...