POJ3080 Blue Jeans
题目链接。
题目大意:
给定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的更多相关文章
- POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()
题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ3080——Blue Jeans(暴力+字符串匹配)
Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...
- poj3080 Blue Jeans【KMP】【暴力】
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions:21746 Accepted: 9653 Descri ...
- POJ3080 - Blue Jeans(KMP+二分)
题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...
- poj3080 Blue Jeans(暴枚+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- POJ3080 Blue Jeans 题解 KMP算法
题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
随机推荐
- poj--1579--(DFS+记忆化搜索之经典)
记忆化搜索 记忆化搜索:算法上依然是搜索的流程,但是搜索到的一些解用 动态规划的那种思想和模式作一些保存. 一般说来,动态规划总要遍历所有的状态,而搜索可以排除一些无效状态. 更重要的是搜索还可以 ...
- Audio Capture 录音
The Android multimedia framework includes support for capturing and encoding a variety of common aud ...
- Ouath协议
OAuth是一个开放协议,允许用户让第三方应用以安全且标准的方式获取该用户在某一网站.移动或桌面应用上存储的私密的资源(如用户个人信息.照片.视频.联系人列表),而无需将用户名和密码提供给第三方应用. ...
- codevs1404字符串匹配
/* 无奈我改了那么久还是看的题解 首先跑一边kmp 几下ans[p]表示总共匹配到长度p的次数 这些不一定都是恰好到p 所以在处理一下 ans[p]通过处理变成 所有的匹配到长度p的次数 最后答案就 ...
- HDU5311
题意:给一个指定的字符串a,要求分成三段,然后再给定另外一个字符串b,要求a中的三段能否在b中找到. 思路:枚举+模拟,首先枚举给定的字符串a,因为分成三段,所以一共有(1+9)*9/2种情况,对于分 ...
- LINQ to SQL 基础
取得数据库Gateway 要操作数据库,我们首先要获得一个DataContext对象,这个对象相当于一个数据 库的Gateway,所有的操作都是通过它进行的.这个对象的名字是“Linq to SQL ...
- (转)PHP函数spl_autoload_register()用法和__autoload()介绍
转--http://www.jb51.net/article/29624.htm 又是框架冲突导致__autoload()失效,用spl_autoload_register()重构一下,问题解决 ...
- jquery val() and text().
.val() works on input elements (or any element with a value attribute?) and .text() will not work on ...
- SQL 中的好习惯和坏习惯
在程序员日常的工作中,SQL可以说不可避免的,高效的SQL可以带来更加愉悦的体验.好的SQL书写习惯会给我们的工作带来极大的好处.简单总结下SQL的好习惯和坏习惯. IN和NOT IN 操作符 编码中 ...
- 使用ul,添加新闻信息列表
在浏览网页时,你会发现网页上有很多信息的列表,如新闻列表.图片列表,如下图所示. 新闻列表 图片列表 这些列表就可以使用ul-li标签来完成.ul-li是没有前后顺序的信息列表. 语法: <ul ...