POJ 3080 Blue Jeans(Java暴力)
Blue Jeans
【题目链接】Blue Jeans
【题目类型】Java暴力
&题意:
就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10
规定:
1、 最长公共串长度小于3不输出
2、 若出现等长的最长的子串,则输出字典序最小的串
&题解:
这个我刚开始用c++写的,真的是恶心到我了,啥都要自己实现,所以突然就想到用Java试试,结果还真的挺简单.思路就是在第1个串中找出所有子串,之后去下面找就行了.
String.compareTo(Sting )是字符串比较; subString 区间是 [ , ) 左闭右开的; String.indexOf(str) 是返回str在字符串中第一次出现的位置,如果没有就返回-1
注意: 1.package zz 是不能放在提交代码里的 否则会Runtime Error
2.public static void main 中的static 不能去掉 否则会Runtime Error
&代码:
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
static boolean ok(String t,int n,String s[]) {
for(int i=1;i<n;i++) {
if(s[i].indexOf(t)==-1) {
return false;
}
}
return true;
}
public static void main(String[] args) throws Exception{
Scanner cin=new Scanner(System.in);
int t=cin.nextInt();
while(t-->0) {
int n=cin.nextInt();
String[] s=new String[23];
// System.out.println("n="+n);
s[0]=cin.nextLine();
for(int i=0;i<n;i++) {
s[i]=cin.nextLine();
// System.out.println("s["+i+"]="+s[i]);
}
String ans="";
for(int i=0;i<s[0].length();i++) {
for(int j=i;j<s[0].length();j++) {
String te=s[0].substring(i, j+1);
if(ok(te,n,s)) {
// System.out.println(te);
// System.out.println(ans+" ===");
if(ans.length()<te.length()) {
ans=te;
}
if(ans.length()==te.length()&&ans.compareTo(te)>0) {
ans=te;
}
}
}
}
if(ans.length()>=3) System.out.println(ans);
else System.out.println("no significant commonalities");
// System.out.println(ok("AGATAC",n,s));
}
cin.close();
}
}
POJ 3080 Blue Jeans(Java暴力)的更多相关文章
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- POJ 3080 Blue Jeans (字符串处理暴力枚举)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21078 Accepted: ...
- POJ 3080 Blue Jeans 找最长公共子串(暴力模拟+KMP匹配)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20966 Accepted: 9279 Descr ...
- poj 3080 Blue Jeans
点击打开链接 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10243 Accepted: 434 ...
- POJ 3080 Blue Jeans (多个字符串的最长公共序列,暴力比较)
题意:给出m个字符串,找出其中的最长公共子序列,如果相同长度的有多个,输出按字母排序中的第一个. 思路:数据小,因此枚举第一个字符串的所有子字符串s,再一个个比较,是否为其它字符串的字串.判断是否为字 ...
- poj 3080 Blue Jeans (暴力枚举子串+kmp)
Description The Genographic Project is a research partnership between IBM and The National Geographi ...
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
- POJ 3080 Blue Jeans 后缀数组, 高度数组 难度:1
题目 http://poj.org/problem?id=3080 题意 有m个(2<=m<=10)不包含空格的字符串,长度为60个字符,求所有字符串中都出现过的最长公共子序列,若该子序列 ...
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...
随机推荐
- lbs@node(lbs asp blog 移植到 nodejs)
lbs@node 2018年的4月26日,我在自己的idea清单中,加上了一条"基于 nodejs 移植 lbs 博客系统". 一.lbs 是什么东东? 它是一款比较小众的博客程序 ...
- 更改Nginx网站根目录以及导致的403 forbidden问题解决
版权声明:本文为博主原创文章,未经博主允许不得转载. 一.更改根目录 Nginx默认网站根目录为/usr/local/nginx/html,要将它改成/home/fuxiao/www 更改方法: ...
- Idea2018旗舰版破解方法
完整请参考 https://www.jianshu.com/p/3c87487e7121 1.在hosts文件里添加一行: 0.0.0.0 account.jetbrains.com 2.在Activ ...
- CentOS上安装配置Ruby on Rails
0.install sublime editor(optional) ref:http://www.tecmint.com/install-sublime-text-editor-in-linux/ ...
- 网络编程 -- RPC实现原理 -- 目录
-- 啦啦啦 -- 网络编程 -- RPC实现原理 -- NIO单线程 网络编程 -- RPC实现原理 -- NIO多线程 -- 迭代版本V1 网络编程 -- RPC实现原理 -- NIO多线程 -- ...
- iOS开发之--UIImageView的animationImages动画
图片动画实现,代码如下: -(UIImageView *)animationImageView { if (!_animationImageView) { _animationImageView= [ ...
- 【Python】博客信息爬取-微信消息自动发送
1.环境安装 python -m pip install --upgrade pip pip install bs4 pip install wxpy pip install lxml 2.博客爬取及 ...
- sql知识点记录
order by就是排序. group by就是分组. WHERE语句在GROUP BY语句之前:SQL会在分组之前计算WHERE语句. HAVING语句在GROUP BY语句之后:SQL会在分 ...
- Linux awk sort
2018-05-31 15:56:38|25961|Cmd_Hero_GetFreeHeros_CS|2|481|0|14|222018-05-31 15:56:38|25961|Cmd_Role_G ...
- js call 理解
首先直接放定义: 总结 1.前提:fun是函数 2.thisArg是在fun函数运行时 指定的this值 1.使用call来继承,新函数使用已经定义好的函数里的方法 下面直接上实例 函数b直接使用函 ...