题目链接

题目大意:

给定n个字符串,找出最长相同且长度大于3的子串,如果存在多个,找出字典序最小的。

分析:

直接枚举(暴搜)。

对于s[0]的每一个子串,判断是否在其它n-1个字符串中都存在。

#include <iostream>
#include <cstdio>
#include <string>
#include <map> using namespace std; #define N 60 string s[], str, str_max; int main(){
int T, n, max_len; scanf("%d", &T); while(T--) {
scanf("%d", &n);
max_len = ;
m.clear(); for(int i=; i<n; i++) {
cin >> s[i];
} for(int i=; i<N; i++) {
for(int j=i+-; j<N; j++) {
if(j-i+ < max_len) continue;
str = s[].substr(i, j-i+);
int k;
for(k=; k<n; k++) {
if(s[k].find(str) == s[k].npos) { //未找到
break;
}
} if(k >= n && str.length() >= max_len) { //找到
if(str.length() == max_len){
if(str < str_max) str_max = str;
}
else {
max_len = str.length();
str_max = str;
}
}
}
} if(max_len) cout << str_max << endl;
else printf("no significant commonalities\n");
} return ;
}

POJ3080 Blue Jeans的更多相关文章

  1. POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()

    题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. POJ3080——Blue Jeans(暴力+字符串匹配)

    Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...

  3. poj3080 Blue Jeans【KMP】【暴力】

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:21746   Accepted: 9653 Descri ...

  4. POJ3080 - Blue Jeans(KMP+二分)

    题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...

  5. poj3080 Blue Jeans(暴枚+kmp)

    Description The Genographic Project is a research partnership between IBM and The National Geographi ...

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

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

  7. POJ3080 Blue Jeans 题解 KMP算法

    题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...

  8. poj 3080 Blue Jeans

    点击打开链接 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10243   Accepted: 434 ...

  9. POJ 3080 Blue Jeans (字符串处理暴力枚举)

    Blue Jeans  Time Limit: 1000MS        Memory Limit: 65536K Total Submissions: 21078        Accepted: ...

随机推荐

  1. Android(java)学习笔记241:多媒体之 MediaPlayer使用

    MediaPlayer类可用于控制音频/视频文件或流的播放.关于如何使用这个类的方法还可以阅读VideoView类的文档. 1.MediaPlayer 状态图       对播放音频/视频文件和流的控 ...

  2. jquery在ie浏览器下中文乱码的问题

    用jquery的ajax方法在调用后台数据发现中文乱码,无法解析中文的url,而在别的浏览器下面就不会,如下所示 $.ajax({ type:'get', url:'薛之谦-演员.lrc', asyn ...

  3. service redis does not support chkconfig的解决办法

    原文链接: http://my.oschina.net/maczhao/blog/322931 问题解决办法如下: 必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中: # ch ...

  4. js select 实现左右传值.html

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

  5. codevs 1213 解的个数(我去年打了个表 - -)

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; int T,x ...

  6. 很棒的jQuery代码片段分享

    jQuery实现的内链接平滑滚动 不需要使用太复杂的插件,只要使用下载这段代码即可实现基于内部链接的平滑滚动 $('a[href^="#"]').bind('click.smoot ...

  7. Mac下配置node.js 和react-native

    最近对JS挺感兴趣的,就琢磨着在mac上配置下环境学习学习,正巧看到了Facebook的react-native,顺便配置了一下. 安装Homebrew 终端输入: ruby -e "$(c ...

  8. Linux 寻找安装路径

    1.whereis 语法:  # whereis [-bmsu] 文件或者目录名称  参数说 明:  -b : 只找二进制文件  -m: 只找在说明文件manual路径下的文件  -s : 只找sou ...

  9. Media Queries详解--转

    Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码:  <link href="css/reset.css" rel ...

  10. QComboBox实现复选功能

    需求: 下拉列表有复选功能 不可编辑 显示所有选中项   关于QComboBox的复选功能有几种方案: QStandardItemModel + QStandardItem QListWidget + ...