hdu-2328(暴力枚举+kmp)
题意:给你n个字符串,问你这n个串的最长公共子串
解题思路:暴力枚举任意一个字符串的所有子串,然后暴力匹配,和hdu1238差不多的思路吧,这里用string解决的;
代码:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
string t;
int main()
{
int n;
string a[4050];
ios::sync_with_stdio(0);
while((cin>>n)&&n)
{
int cot;
int maxx=0;
for(int i=1;i<=n;i++)
cin>>a[i];
int len=a[1].size();
for(int i=0;i<len;i++)
{
for(int j=1;j<=len-i;j++)
{
if(j<maxx)
continue;
cot=0;
for(int k=2;k<=n;k++)
{
if(a[k].find(a[1].substr(i,j))==string::npos)
break;
else
cot++;
}
if(cot==n-1)
{
// cout<<a[1].substr(i,j)<<endl;
if(j>maxx)
{
maxx=j;t=a[1].substr(i,j);
}
else if(j==maxx)
{
if(t>a[1].substr(i,j))
t=a[1].substr(i,j);
}
}
}
}
if(maxx==0)
cout<<"IDENTITY LOST";
else
cout<<t;
cout<<endl;
}
}
hdu-2328(暴力枚举+kmp)的更多相关文章
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 2328 POJ 3450 KMP
题目链接: HDU http://acm.hdu.edu.cn/showproblem.php?pid=2328 POJhttp://poj.org/problem?id=3450 #include ...
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- hdu 4414 暴力枚举
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- HDU:3368-Reversi(暴力枚举)
Reversi Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- hdu_2328_Corporate Identity(暴力枚举子串+KMP)
题目链接:hdu_2328_Corporate Identity 题意: 给你n个串,让你找这n个串的最大公共子串 题解: 串比较小,暴力枚举第一个的子串,然后KMP判断是否可行 #include&l ...
- HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举
HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
随机推荐
- mac sourcetree push分支选中所有tag的时候报错
错误信息: ....... ! [rejected] 573_0811_stable -> 573_0811_stable (already exists)updating local trac ...
- c# 设置IE浏览器版本运行程序-设置webBrowser对应的IE内核版本来运行
//通常情况下,我们直接调用C#的webBrowser控件,默认的浏览器内核是IE7. 那么如何修改控件调用的默认浏览器版本呢?using System; using System.Collecti ...
- 448C - Painting Fence(分治)
题意:给出宽为1高为Ai的木板n条,排成一排,每次上色只能是连续的横或竖并且宽度为1,问最少刷多少次可以使这些木板都上上色 分析:刷的第一步要么是所有的都竖着涂完,要么是先横着把最矮的涂完,如果是第一 ...
- Spring Boot 中使用 @Transactional 注解配置事务管理
事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...
- eclipse中不能保存汉字的解决方法
首先分清是打开jsp页面的问题还是java文件的问题? 对于java文件,只要在你的项目上点击右键选择“Propertise”(属性)然后点击“Info”标签将里面的Text file enco ...
- 【学习总结】Git学习-参考廖雪峰老师教程一-Git简介
学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...
- How To: Capture Android & iOS Traffic with Fiddler
How To: Capture iOS Traffic with Fiddlerhttps://www.telerik.com/blogs/how-to-capture-ios-traffic-wit ...
- [转帖]CentOS 6 服务器安全配置指南(通用)
CentOS 6 服务器安全配置指南(通用) http://seanlook.com/2014/09/07/linux-security-general-settings/ 发表于 2014-09- ...
- 【学亮开讲】Oracle内外连接查询20181119
--内连接查询 --需求:查询显示业主编号.业主名称.业主类型名称 select os.id 业主编号,os.name 业主名称,ot.name 业主类型名称 from t_owners os,t_o ...
- JS 将值插入数组中
使用 push 方法 1.var arr = [1,2,3] arr.push(数值) 或者 arr.push({xxx:数值}) 2.输出数组中的最后一个 console.log(arr.[arr. ...