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: ...
随机推荐
- MySQL更新时Error Code:1093和Error Code:1175的解决办法
Error Code: 1093. You can't specify target table 'ws_product' for update in FROM clause 这个是我们在使用upda ...
- UVA 11212 IDA*
移动一块连续的区间使得数列递增.问最少次数. 直接IDA*暴搜,只是我没有想到A*函数,所以就随手写了个连续递增块数作为估价函数,WA了,然后除以2,还是WA,除以3,WA,除以4...过了= = # ...
- [PWA] 18. Clean the photo cache
We cannot let photo always keep caching new data without clean the old data. If message is not displ ...
- cocos2dx c++ 在mac下写的中文凝视,在win32下编译时不通过
今天遇到个奇怪的问题,在mac下写的程序,加的中文凝视,编译没有问题,可是在win32下(使用的时vs2012, win7 64bit 系统)编译就总是报错 最后在中文凝视后 加一个空格,或者 换行, ...
- python----------反射和设计模式
反射: 把字符串映动态射成对象内存地址. hasattr():判断一个对象里是否有对应的字符串的方法 getattr():根据字符串去获取obj对象里的对应方法的内存地址. class Dog(obj ...
- asp.net服务器控件防止多次提交问题
用户可能点击多次提交按钮.这样,导致向数据库中插入了多条相同的记录. 好像这2个方法都是针对的服务器控件! //方法一:在提交时调用一段客户端的代码. function a() { document. ...
- php创建读取 word.doc文档
创建文档; <?php $html = "this is question"; for($i=1;$i<=3;$i++){ $word = new word(); $w ...
- datediff(),dateadd(),datepart().datename()时间处理函数
原文链接:http://www.cnblogs.com/whz111/articles/2445777.html --convert(时间)对应数字表示的时间格式 select CONVERT(var ...
- C#实现自动切割图片
由于做一个TD游戏需要一些图片素材,可是现有的从网上下载的<保卫萝卜>的图片资源是多张图片合在一起的,并且没有什么规则,虽然有 个xml文件似乎用来描述此图片内子图片位置大小等信息,但由于 ...
- SQL 中的好习惯和坏习惯
在程序员日常的工作中,SQL可以说不可避免的,高效的SQL可以带来更加愉悦的体验.好的SQL书写习惯会给我们的工作带来极大的好处.简单总结下SQL的好习惯和坏习惯. IN和NOT IN 操作符 编码中 ...