OpenJudge/Poj 1226 Substrings
1.链接地址:
http://bailian.openjudge.cn/practice/1226/
http://poj.org/problem?id=1226
2.题目:
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
- You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.
- 输入
- The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.
- 输出
- There should be one line per test case containing the length of the largest string found.
- 样例输入
2
3
ABCD
BCDFF
BRCD
2
rose
orchid- 样例输出
2
2- 来源
- Tehran 2002 Preliminery
3.思路:
4.代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
using namespace std;
const int NUM = ;
char strs[NUM][NUM + ];
int main()
{
//freopen("F:\\input.txt","r",stdin);
int i,j,k; int t;
cin>>t; int n,length;
while(t--)
{
cin>>n;
cin.get(); for(i = ; i < n; i++)
{
scanf("%s",strs[i]);
} for(i = ; i < n; i++) length = strlen(strs[]);
char substr[NUM + ],substr2[NUM + ];
int res = ;
for(i = ; i <= length; i++)
{
for(j = ; (j+i-) < length; j++)
{
strncpy(substr,&strs[][j],i);
substr[i] = '\0';
strcpy(substr2,substr); for(k = ; k < (i+)/; k++)
{
char tmp = substr2[k];
substr2[k] = substr2[i--k];
substr2[i--k] = tmp;
} //cout<<"substr="<<substr<<",substr2="<<substr2<<endl;
for(k = ; k < n; k++)
{
if(!strstr(strs[k],substr) && !strstr(strs[k],substr2)) break;
}
if(k >= n )
{
res = i;
break;
}
}
} cout<<res<<endl;
}
return ;
}
OpenJudge/Poj 1226 Substrings的更多相关文章
- POJ - 1226 Substrings (后缀数组)
传送门:POJ - 1226 这个题跟POJ - 3294 和POJ - 3450 都是一样的思路,一种题型. POJ - 3294的题解可以见:https://www.cnblogs.com/li ...
- POJ 1226 Substrings(后缀数组+二分答案)
[题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...
- POJ 1226 Substrings
Substrings Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: ...
- POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)
多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...
- 【POJ 1226】Substrings
[链接]h在这里写链接 [题意] 给你n个字符串. 让你找一个字符串s. 设s'为这个字符串的逆序. 要求s或者s'在每个字符串里都能够找得到. 并且要求s的长度最长. 求出这个最长的串的长度. [题 ...
- POJ 1226 后缀数组
题目链接:http://poj.org/problem?id=1226 题意:给定n个字符串[只含大小写字母],求一个字符串要求在n个串或者他们翻转后的串的出现过.输出满足要求的字符串的长度 思路:根 ...
- OpenJudge / Poj 2141 Message Decowding
1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...
- OpenJudge/Poj 2105 IP Address
1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...
- OpenJudge/Poj 2027 No Brainer
1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...
随机推荐
- mac磁盘满解决方案
背景 : 用mac电脑的人,估计都不习惯去关机吧.mac虽然可以不需要关闭电脑,但是久而久之由于应用软件占用产生缓存文件 or 产生虚拟内容交换文件 or 睡眠镜像文件 and so on. 会占用大 ...
- android studio 更改背景和设置字体大小
1,设置字体大小 2,设置背景主题
- hadoop安装与WordCount例子
1.JDK安装 下载网址: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u29-download-513648.html ...
- EasyUI基础入门之Easyloader(载入器)
在了解完easyui的parser(解析器)之后,接下来就是easyloader(简单载入器)的学习了. 什么是EasyLoader 正如其名字一样easyloader的作用是为了动态的载入组件所需的 ...
- ios开发——笔记篇
:开关 BOOL isopen = !isopen; //View @property (nonatomic, assign) BOOL open;//模型属性 self.group.open = ! ...
- iOS开发——UI篇OC篇&UITableView多项选择
UITableView多项选择 自定义cell和取到相应的cell就行了 TableViewCell.h #import <UIKit/UIKit.h> @interface TableV ...
- 带缓冲I/O和不带缓冲I/O的区别与联系
转自:http://blog.csdn.net/lmh12506/article/details/6803847 首先要明白不带缓冲的概念:所谓不带缓冲,并不是指内核不提供缓冲,而是只单纯的系统调用, ...
- Android(java)学习笔记133:ListViewProject案例(ListView + BaseAdapter + CheckBox)
这个案例可能稍微复杂一点,我会讲述详细一点: 1.首先是AndroidManifest.xml: <?xml version="1.0" encoding="utf ...
- Java设计模式之策略模式(一)
今年寒假没有回家,打算利用这个假期的时间进行学习设计模式,这一个人感觉比较牛的知识,前一段时间一直在忙着搞自己的专业课,还有就是捣鼓了一下Linux系统,没有好好的学习关于Java还有Android方 ...
- Linux上安装Squall
Squall是Storm之上的类SQL查询工具,能够将类SQL语句转换成topology,然后提交给Storm运行. 安装Squall前要先安装Java和sbt(simple build tool), ...