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 ...
随机推荐
- oracle 删除用户,表空间;循环删除表
select * from dba_tablespaces 说明:查看所有表空间 ----------------------------------------------------------- ...
- 【转载】VMWare ESXi 5.0和vSphere Client安装和配置
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:张洪洋_ 原文地址:http://blog.sina.com.cn ...
- NC保存报dirty解决方法
在NC UI端测试保存的时候报 " The data whose initcode is 6033 is dirty! " 错误,其解决方式是 在IHrPf接口中添加你的单据模板编号 和 参数模板 ...
- Sqlitekit 封装管理
最近需要用到Sqlite数据库来做一个游戏的数据存储.网上搜了一下,两种方法,一种是自己dll搭建环境有可能还需要编译之类的,我自己是搭建出来了,不过我没采用. 还有一种就是使用sqlitekit插件 ...
- NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
解决办法: http://stackoverflow.com/questions/4037125/namespace-err-an-attempt-is-made-to-create-or-chang ...
- 欧拉工程第72题:Counting fractions
题目链接:https://projecteuler.net/problem=72 真分数;n/d 当d ≤ 1,000,000时候的真分数有多少个 public class P72{ void run ...
- Libsvm学习
本篇博客转自 http://www.cppblog.com/guijie/archive/2013/09/05/169034.html 在电脑文件夹E:\other\matlab 20 ...
- 【转】Windows Server 2008修改远程桌面连接数
按照下面的设置是成功了的,我设置的连接数是5个. http://jingyan.baidu.com/article/154b463150d1b128ca8f4194.html
- 天气API整理,返回的数据格式为json对象
中国天气的API惨遭封杀,不得已更换其他的API使用吧. 这里大部分API来自APP的数据包截取或者反汇编,所以各开发使用者不得用于商业用途,否则后果自负! 1.金山网址导航 来源:http://ww ...
- CentOS7 升级python同时解决yum损坏问题
CentOS7中的python版本为python2.7.5,升级到最新版的python时需要注意两个问题 新版的python安装好后要修改python的系统默认指向问题 升级到最新版python后yu ...