题意:

找出这些串中最长的公共子串(长度≥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的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. 1222: FJ的字符串 [水题]

    1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1  =  “A” A2  =   ...

  3. 1001 字符串“水”题(二进制,map,哈希)

    1001: 字符串“水”题 时间限制: 1 Sec  内存限制: 128 MB提交: 210  解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...

  4. (字符串 KMP)Blue Jeans -- POJ -- 3080:

    链接: http://poj.org/problem?id=3080 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88230#probl ...

  5. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  6. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  7. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  8. HDU ACM 1073 Online Judge -&gt;字符串水题

    分析:水题. #include<iostream> using namespace std; #define N 5050 char a[N],b[N],tmp[N]; void Read ...

  9. HDU4891_The Great Pan_字符串水题

    2014多校第五题,当时题面上的10^5写成105,我们大家都wa了几发,改正后我和一血就差几秒…不能忍 题目:http://acm.hdu.edu.cn/showproblem.php?pid=48 ...

随机推荐

  1. NeatUpload 同时选择并上传多个文件

    neatUpload是asp.net 中可以同时上传多个文件的控件,主页:http://neatupload.codeplex.com/. 效果如下图(显示有点不正常...): 使用步骤: 1. 在a ...

  2. Codeforces Beta Round #10 D. LCIS

    题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...

  3. 奇异值分解(We Recommend a Singular Value Decomposition)

    奇异值分解(We Recommend a Singular Value Decomposition) 原文作者:David Austin原文链接: http://www.ams.org/samplin ...

  4. SDUT2141数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<cstdio> #include& ...

  5. Happy Number

    https://leetcode.com/problems/happy-number/ Write an algorithm to determine if a number is "hap ...

  6. Spring整合Ibatis

    Spring整合Ibatis javaibatisspring 所需jar清单           ibatis-2.*.jar    *为任意版本,下同,ibatis工作包           sp ...

  7. Win7-其中的文件夹或文件已在另一个程序中打开

    Win7-其中的文件夹或文件已在另一个程序中打开 如何解决Win7系统在删除或移动文件时提示,“操作无法完成,因为其中的文件夹或文件已在另一个程序中打开,请关闭该文件夹或文件,然后重试”.   步骤阅 ...

  8. python 获取当前调用函数名等log信息

    import sys funcName = sys._getframe().f_back.f_code.co_name #获取调用函数名 lineNumber = sys._getframe().f_ ...

  9. I²C接口学习总结

    1.IIC总线概念:   a.只有两条总线线路:一条串行数据线,一条串行时钟线.   b.每个连接到总线的器件都可以使用软件根据它们的唯一的地址来识别.   c.传输数据的设备间是简单的主从关系.   ...

  10. 卓京---java基础2

    2.数据类型 基本类型: 整型: byte字节型   8位(bit) -2^7~2^7-1(-128~127)  0000 0000 short短整型  16位 -2^15~2^15-1(-32768 ...