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的更多相关文章

  1. POJ - 1226 Substrings (后缀数组)

    传送门:POJ - 1226 这个题跟POJ - 3294  和POJ - 3450 都是一样的思路,一种题型. POJ - 3294的题解可以见:https://www.cnblogs.com/li ...

  2. POJ 1226 Substrings(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...

  3. POJ 1226 Substrings

    Substrings Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: ...

  4. POJ - 3294~Relevant Phrases of Annihilation SPOJ - PHRASES~Substrings POJ - 1226~POJ - 3450 ~ POJ - 3080 (后缀数组求解多个串的公共字串问题)

    多个字符串的相关问题 这类问题的一个常用做法是,先将所有的字符串连接起来, 然后求后缀数组 和 height 数组,再利用 height 数组进行求解. 这中间可能需要二分答案. POJ - 3294 ...

  5. 【POJ 1226】Substrings

    [链接]h在这里写链接 [题意] 给你n个字符串. 让你找一个字符串s. 设s'为这个字符串的逆序. 要求s或者s'在每个字符串里都能够找得到. 并且要求s的长度最长. 求出这个最长的串的长度. [题 ...

  6. POJ 1226 后缀数组

    题目链接:http://poj.org/problem?id=1226 题意:给定n个字符串[只含大小写字母],求一个字符串要求在n个串或者他们翻转后的串的出现过.输出满足要求的字符串的长度 思路:根 ...

  7. OpenJudge / Poj 2141 Message Decowding

    1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...

  8. OpenJudge/Poj 2105 IP Address

    1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...

  9. OpenJudge/Poj 2027 No Brainer

    1.链接地址: http://bailian.openjudge.cn/practice/2027 http://poj.org/problem?id=2027 2.题目: 总Time Limit: ...

随机推荐

  1. ecshop后台admin文件夹任意更改名

    为了ecshop网站安全起见或不想泄露后台的路径,那么我们必须修改后台admin文件夹名称. 方法和步骤如下: 把原admin文件夹名改成edait为例来说明 首先,把商城根目录下的admin文件夹重 ...

  2. 对PostgreSQL xmax的理解

    xmax The identity (transaction ID) of the deleting transaction, or zero for an undeleted row version ...

  3. Jquery easyui treegrid实现树形表格的行拖拽

    前几天修改了系统的一个功能——实现树形列列表的行拖拽,以达到排序的目的.现在基本上功能实现,现做一个简单的总结. 1.拿到这个直接网上搜,有好多,但是看了后都觉得不是太复杂就是些不是特别想看的例子,自 ...

  4. EXE文件结构及读取方法

    一.EXE文件概念 EXE File英文全名executable file ,译作可运行文件,可移植可运行 (PE) 文件格式的文件,它能够载入到内存中,并由操作系统载入程序运行.是可在操作系统存储空 ...

  5. Android Intent入门

    http://www.cnblogs.com/leipei2352/archive/2011/08/09/2132096.html http://blog.csdn.net/xiazdong/arti ...

  6. 《Linux内核修炼之道》 之 高效学习Linux内核

    http://blog.csdn.net/fudan_abc/article/details/5738436

  7. webService 讲解

    Web Service简介: Web Service 是构建互联网分布式系统的基本部件,可以将具有特定功能或者可复用应用程序封装. 技术组成要素: SOAP:Web Service的基本通信协议,由普 ...

  8. Linux下各种常见环境变量的配置

      Linux系统下各种环境变量都通过修改/etc/profile文件来实现.由于是系统文件,修改此文件需要root权限.因此实现以下功能都需要用户拥有root权限. 另:不要轻易修改profile文 ...

  9. linux中的工具

    远程连接linux的工具: 命令行: SecureCRT   putty  XShell(商业环境付费) 图形界面:WinSCP SecureFX 远程连接window服务器工具: FileZilla ...

  10. php代理请求

    $url = 'http://192.168.5.241:8893/index.php?a=SendMessage&m=taskSend'; $ci = curl_init ();/* Cur ...