POJ 3080 (字符串水题) Blue Jeans
题意:
找出这些串中最长的公共子串(长度≥3),如果长度相同输出字典序最小的那个。
分析:
用库函数strstr直接查找就好了,用KMP反而是杀鸡用牛刀。
#include <cstdio>
#include <cstring> char a[][], sub[];
int p[], l; int cmp(int p1, int p2)
{
for(int i = ; i < l; ++i)
if(a[][p1 + l] > a[][p2 + l]) return p2;
return p1;
} int main(void)
{
//freopen("3080in.txt", "r", stdin);
int T;
scanf("%d", &T);
while(T--)
{
int n, cnt = ;
scanf("%d", &n);
for(int i = ; i < n; ++i) scanf("%s", a[i]); for(l = ; l >= ; --l)
{
cnt = ;
for(int pos = ; pos <= - l; ++pos)
{
char temp = a[][pos + l];
a[][pos + l] = '\0';
bool flag = true;
for(int i = ; i < n; ++i)
{
if(strstr(a[i], a[] + pos) == NULL)
{
flag = false;
break;
}
if(!flag) break;
}
a[][pos + l] = temp;
if(flag)
p[cnt++] = pos;
}
if(cnt > ) break;
} if(cnt == )
{
puts("no significant commonalities");
continue;
} int min = p[];
for(int i = ; i < cnt; ++i) min = cmp(min, p[i]);
a[][min + l] = '\0';
printf("%s\n", a[] + min);
} return ;
}
代码君
POJ 3080 (字符串水题) Blue Jeans的更多相关文章
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 1222: FJ的字符串 [水题]
1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = ...
- 1001 字符串“水”题(二进制,map,哈希)
1001: 字符串“水”题 时间限制: 1 Sec 内存限制: 128 MB提交: 210 解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...
- (字符串 KMP)Blue Jeans -- POJ -- 3080:
链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- poj 3264 RMQ 水题
题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- Poj 1552 Doubles(水题)
一.Description As part of an arithmetic competency program, your students will be given randomly gene ...
- HDU ACM 1073 Online Judge ->字符串水题
分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...
- HDU4891_The Great Pan_字符串水题
2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...
随机推荐
- 设计模式之原型模式(prototype)
原理:拷贝自身对象实际上就是调用的拷贝构造函数,注意事项是这里的拷贝是深拷贝,即需要拷贝指针所指的内容 #include <stdio.h> #include <memory> ...
- [转载]C#中的WebBrowser控件的使用
http://www.cnblogs.com/txw1958/archive/2012/09/24/CSharp-WebBrowser.html
- 高性能网络编程1----accept建立连接
转 http://taohui.org.cn/tcpperf1.html 陶辉 taohui.org.cn 回到应用层,往往只需要调用类似于accept的API就可以建立TCP连接.建立连接的流程大 ...
- oracle RAC--归档日志的开启方法
oracle RAC--归档日志的开启方法 2011-10-07 15:53:04 分类: Oracle oracle RAC--归档日志的开启方法 ======================= ...
- 一天,python搞个分析NGINX日志的脚本
准备给ZABBIX用的. 统计接口访问字次,平均响应时间,4XX,5XX次数 以后可以再改进.. #!/usr/bin/env python # coding: utf-8 ############# ...
- Strust2最基本使用
制作一个登陆表单,然后在另一个页面显示提交的内容,简单的一个小工程. 页面: //login.jsp <form action="login.action" method=& ...
- lintcode:Binary Search 二分查找
题目: 二分查找 给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1. 样例 ...
- Libsvm学习
本篇博客转自 http://www.cppblog.com/guijie/archive/2013/09/05/169034.html 在电脑文件夹E:\other\matlab 20 ...
- sparse coding稀疏表达入门
最近在看sparse and redundant representations这本书,进度比较慢,不过力争看过的都懂,不把时间浪费掉.才看完了不到3页吧,书上基本给出了稀疏表达的概念以及传统的求法. ...
- 缓存初解(三)---Spring3.0基于注解的缓存配置+Ehcache和OScache
本文将构建一个普通工程来说明spring注解缓存的使用方式,关于如何在web应用中使用注解缓存,请参见: Spring基于注解的缓存配置--web应用实例 一.简介 在spring的modules包中 ...