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: ...
随机推荐
- ListOrderedMap
要有序能够用List,要便于查找能够用Map,那既要有序又便于查找呢? 近期我就遇到了这样一个问题.Java没有给我们提供现成的类.我们全然能够自己开发个类继承List和Map(Java原来就有不能够 ...
- C#-datagridview隐藏行头
在进行datagridview的设置的过程中,常常会遇到需要设定datagridview1的行头显示,这就需要用到datagridview的属性: RowHeadersVisible属性设置为fals ...
- springMVC3学习(五)--MultiActionController
Spring提供一个多动作控制器,使用它你能够将几个动作合并在一个控制器里,这样能够把功能组合在一起. 多动作控制器存在在一个单独的包中--org.springframework.web.mvc.mu ...
- android的界面编程
主要是用View以及ViewGroup,同时ViewGroup又是View的子类,充当容器. 主要有两种方法控制view的行为: 1.在XML布局文件中通过XML属性进行控制 2.在Java代码中通过 ...
- PHP算法--将数字金额转换成大写金额
最近在看一些PHP算法题,遇到一个将数字金额转换成大写金额的小算法题,这里贴出自己的一个例子. 注:这个小算法适用于10万以内的金额. <?php //$num = 12345.67; func ...
- Tomcat启动报错 Failed to start component [StandardServer[8005]]解决
SEVERE: The required Server component failed to start so Tomcat is unable to start. org.apache.catal ...
- Linux 的使用基础---Shell程序设计
Shell是Linux系统中的一个重要的层次,它是用户与系统交互作用的界面.Shell除了作为命令解释程序以外,还是一种高级程序设计语言.利用Shell程序设计语言可以编写出功能很强.但代码简单的程序 ...
- 【转】web测试方法总结
一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号.禁止直接输入特殊字符时 ...
- CentOS 7.x安装ELK(Elasticsearch+Logstash+Kibana)
第一次听到ELK,是新浪的@ARGV 介绍内部使用ELK的情况和场景,当时触动很大,原来有那么方便的方式来收集日志和展现,有了这样的工具,你干完坏事,删除日志,就已经没啥作用了. 很多企业都表示出他们 ...
- 用于主题检测的临时日志(fe4edac1-b4f4-4673-ae87-110cbb7dbb5a - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
这是一个未删除的临时日志.请手动删除它.(25ea5485-9168-424b-a30c-09cc1371e2d9 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)