题目链接

题目大意:

给定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的更多相关文章

  1. POJ3080 Blue Jeans —— 暴力枚举 + KMP / strstr()

    题目链接:https://vjudge.net/problem/POJ-3080 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total ...

  2. POJ3080——Blue Jeans(暴力+字符串匹配)

    Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...

  3. poj3080 Blue Jeans【KMP】【暴力】

    Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:21746   Accepted: 9653 Descri ...

  4. POJ3080 - Blue Jeans(KMP+二分)

    题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...

  5. poj3080 Blue Jeans(暴枚+kmp)

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

  6. kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans

    The Genographic Project is a research partnership between IBM and The National Geographic Society th ...

  7. POJ3080 Blue Jeans 题解 KMP算法

    题目链接:http://poj.org/problem?id=3080 题目大意:给你N个长度为60的字符串(N<=10),求他们的最长公共子串(长度>=3). 题目分析:KMP字符串匹配 ...

  8. poj 3080 Blue Jeans

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

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

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

随机推荐

  1. Swoole源代码学习记录(十五)——Timer模块分析

    swoole版本号:1.7.7-stable Github地址:点此查看 1.Timer 1.1.swTimer_interval_node 声明: // swoole.h 1045-1050h ty ...

  2. 代码讲解Android Scroller、VelocityTracker

    在编写自定义滑动控件时常常会用到Android触摸机制和Scroller及VelocityTracker.Android Touch系统简介(二):实例详解onInterceptTouchEvent与 ...

  3. Win10中英文的切换

    在UAP中,涉及到中英文版本切换,在string目录下面添加资源str 读取的时候 new Windows.ApplicationModel.Resources.ResourceLoader().Ge ...

  4. phpmyadmin安装出错,缺少 mysqli 扩展。请检查 PHP 配置

    下载了个phpmyadmin最新版本的,始终显示这样的内容,求助.如何解决哈?>缺少 mysqli 扩展.请检查 PHP 配置. <a href="Documentation.h ...

  5. iOS开发之字典数据建立模型步骤

    1. 在控制器属性的(questions)set方法中完成字典转模型的操作 - (NSArray *)questions { if (nil == _questions) { //1.加载plist文 ...

  6. [转]Delphi 中动态链接库(dll)的建立和使用

    动态链接库是一个能够被应用程序和其它的DLL调用的过程和函数的集合体,它里面包含的是公共代码或资源.由于DLL代码使用了内存共享技术,在某些地方windows也给了DLL一些更高的权限,因而DLL中可 ...

  7. 在SpringMVC框架下建立Web项目时web.xml到底该写些什么呢?

    刚刚初学Spring MVC,却连一个简单的helloworld都搞的懵懵懂懂的,配置文件搞不清,各种文件之间的逻辑关系也不懂,连续看了好些日子的Spring MVC了,今天终于下定决心,每天记录一点 ...

  8. openMPI小集群安装

    经过一天的努力,终于完成了openMPI的多节点安装,即小集群安装.本文使用的是openmpi-1.6.5,下载地址见:http://www.open-mpi.org/software/ompi/v1 ...

  9. ubuntu忘记登录账户以及密码

    笔者在诸多方面仍然是初学者.感兴趣的方面也很多,电脑装上ubuntu14.04也有一段时间了,但仍然在不断学习更多基础的东西. 因为对于命令行界面还有些不习惯,所以一直依赖于图形界面,需要使用终端的时 ...

  10. 【转载】如何学习javascript

    如何学习Javascript 作者: chaomao  首先要说明的是,咱现在不是高手,最多还是一个半桶水,算是入了JS的门. 谈不上经验,都是一些教训. 这个时候有人要说,“靠,你丫半桶水,凭啥教我 ...