题目链接:

https://vjudge.net/problem/POJ-3080

题目大意:

找最长的公共字串(长度>=3),长度相同就找字典序最小的

解题思路:

枚举第一个串的所以子串,处理出其他串的所有子串,然后set查找,更新ans

 #include<iostream>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
int T;
set<string>tot[];
int main()
{
cin >> T;
while(T--)
{
int n;
string s, s1;
cin >> n;
cin >> s;
for(int i = ; i < n; i++)
{
cin >> s1;
tot[i].clear();
for(int len = ; len <= s1.size(); len++)
{
for(int start = ; start + len <= s1.size(); start++)
{
int end = start + len;
string s2;
for(int j = start; j < end; j++)
s2 += s1[j];
tot[i].insert(s2);
}
}
}
string ans = "";
for(int len = ; len <= s.size(); len++)
{
for(int start = ; start + len <= s.size(); start++)
{
int end = start + len;
string s2;
for(int i = start; i < end; i++)
s2 += s[i];
bool flag = ;
for(int i = ; i < n; i++)
{
if(!tot[i].count(s2))
{
flag = ;
break;
}
}
if(flag)
{
if(s2.size() > ans.size())
{
ans = s2;
}
else if(s2.size() == ans.size() && ans > s2)
{
ans = s2;
}
}
}
}
if(ans.size() < )cout<<"no significant commonalities"<<endl;
else cout<<ans<<endl;
}
}

POJ-3080 Blue Jeans---字符串+暴力的更多相关文章

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

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

  2. POJ 3080 Blue Jeans(Java暴力)

    Blue Jeans [题目链接]Blue Jeans [题目类型]Java暴力 &题意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 规定: 1. 最长公共 ...

  3. POJ 3080 Blue Jeans (求最长公共字符串)

    POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...

  4. POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20966   Accepted: 9279 Descr ...

  5. poj 3080 Blue Jeans

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

  6. POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)

    题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...

  7. poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】

    题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...

  8. poj 3080 Blue Jeans (暴力枚举子串+kmp)

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

  9. POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)

    <题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1.  最长公共串长度小于3输出   no significant co ...

  10. POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1

    题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...

随机推荐

  1. Spring第一天:Spring的概述、SpringIOC入门(XML)、Spring的Bean管理、Spring属性注入

    记得引入约束 上图路径. 此时 只需修改配置文件 便可以随意更换实现类 无需修改代码. 传统方法必须用实现类(不面向接口了)来调用方法设置属性. 而在Spring中:在创建类的过程中发现实现类有nam ...

  2. go培训课程都学什么?go语言框架学习:xorm框架知识介绍

    xorm框架介绍 xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便. 通过xorm框架,开发者可以方便的使用各种封装好的方法来代替原生的sql语句.这样就降低了我们开发者使 ...

  3. Gson本地和服务器环境不同遇到的Date转换问题 Failed to parse date []: Invalid time zone indicator

    GoogleGson在处理Date格式时有个小陷阱,在不同环境中部署时可能会遇到问题. Gson默认处理Date对象的序列化/反序列化是通过一个SimpleDateFormat对象来实现的,通过下面的 ...

  4. python数据类型基本操作

    目录 1.字符串.... 1 2.列表[ ] 3 3.元组 ( ) 4 4.字典 { } 4 5.SET集合... 7 1.字符串 1.1查找字符串 find查找 >>> msg = ...

  5. module.exports 和 export default

    CommonJS模块规范和ES6模块规范完全是两种不同的概念 CommonJS模块规范 Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一 ...

  6. jmeter 正则获取参数集合和ForEach控制器结合使用(转)

    怎么把第一个请求获取的返回的多个id,在第二个请求中逐个以单个id作为请求参数来请求? 为了解决这个问题,模拟下该场景 1.请求www.163.com 主页,获取响应中的所有数字,这个获取的数字集合暂 ...

  7. 论js里面的for循环

    首先搞懂执行的顺序: 对,执行顺序就是这样的. for循环的作用: 1.在编写代码时,你常常希望反复执行同一段代码. 2.遍历数组,可以用forEach();对于DOM对象(nodelist)的话,比 ...

  8. 练习三十八:矩阵for循环应用

    习题如下: 求一个3*3矩阵对角线元素之和 利用for循环控制输出二维数组,再将a[i][j]累加后输出 a = [] sum1 = 0.0 for i in range(3): a.append([ ...

  9. poi操作word文档文件操作

    import org.apache.poi.POITextExtractor; import org.apache.poi.hwpf.extractor.WordExtractor; //得到.doc ...

  10. jQuery读取和设定KindEditor值的方法

    转载自:https://www.jb51.net/article/43595.htm 侵删 jQuery读取和设定KindEditor值的方法 更新时间:2013年11月22日 09:03:56   ...