题目链接:

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. 某人视频中提到的 Spark Streaming 优化的几点事项

    某人,并未提他的名字,是因为看的视频是1年前的,视频里他吹得厉害.我看视频时,查了一下他在视频里说的要做到的东西,结果上网一查,就看到了很多人说他骗了钱后,就不管交了学费的人了.真假无从查起.但是无风 ...

  2. hdu3078(lca / RMQ在线)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3078 题意: 给出一棵 n 个点的带点权值的树, 接下来有 q 组形如 k, x, y 的输入, 若 ...

  3. CF868F Yet Another Minimization Problem(决策单调性)

    题目描述:给定一个序列,要把它分成k个子序列.每个子序列的费用是其中相同元素的对数.求所有子序列的费用之和的最小值. 输入格式:第一行输入n(序列长度)和k(需分子序列段数).下一行有n个数,序列的每 ...

  4. ps怎样简单快速去除图片上的文字

    具体步骤如下: 1.选择"修补工具": 2.在公共栏中选择"源": 3."图像"->"模式"中选择"RG ...

  5. 「模拟赛20180306」回忆树 memory LCA+KMP+AC自动机+树状数组

    题目描述 回忆树是一棵树,树边上有小写字母. 一次回忆是这样的:你想起过往,触及心底--唔,不对,我们要说题目. 这题中我们认为回忆是这样的:给定 \(2\) 个点 \(u,v\) (\(u\) 可能 ...

  6. PAT天梯赛L3-007 天梯地图

    题目链接:点击打开链接 本题要求你实现一个天梯赛专属在线地图,队员输入自己学校所在地和赛场地点后,该地图应该推荐两条路线:一条是最快到达路线:一条是最短距离的路线.题目保证对任意的查询请求,地图上都至 ...

  7. 洛谷P3384【模板】树链剖分

    题目描述 如题,已知一棵包含\(N\)个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作\(1\): 格式: \(1\) \(x\) \(y\) \(z\) 表示将树从\(x\ ...

  8. java 使用 spirng 监控 cpu 使用 状态。。。。

    首先..使用 sigar ,sigar 使用  要 注意区分 是 web 还是 本地..最好 在 WEB-INF 下 复制 dll 文件..因为WEB-INF 不会被压缩... try { //如果是 ...

  9. ThreadFactory 线程池工厂

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Thr ...

  10. Python——连接数据库

    好用的教程(*^▽^*):https://www.cnblogs.com/fatcat132006/p/4081576.html