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: ...
随机推荐
- ECSHOP在线手册布局参考图--登录/注册页 user_passport.dwt
A.会员登录框 1,设置方法 自带模块 2,代码相关 user_passport.dwt 中 <div class="usBox_1 f_l"> <div ...
- java图片处理
import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import ja ...
- 检查class排座位
在写这篇文章之前,xxx已经写过了几篇关于改检查class主题的文章,想要了解的朋友可以去翻一下之前的文章 每日一道理 灯,带有一种明亮的光,每当深夜来临,是它陪伴着你,如此默默无闻.它是平凡 ...
- 本地win8系统部署网站遇到的问题
网站开发环境:vs2013 .操作系统是win8.1系统. iis8 win8系统激活码:00261-30000-00000-AA825 需要部署的网站文件夹放在了桌面上,在iis里配置时,无法启 ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- hdu 5120 Intersection 圆环面积交
Intersection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- UNIX标准化及实现之标准之间的冲突
就整体而言,这些不同的标准之间配合得相当好.但是我们也很关注它们之间的差别,特别是ISO C标准和POSIX.1之间的差别. ISO C定义了函数clock,它返回进程使用的CPU时间,返回值类型是c ...
- Linux 学习笔记 基本的bash shell命令
Linux 文件系统 Linux讲文件存储在单个目录结构(虚拟目录)中,虚拟目录包含了安装在PC上的所有存储设备的文件路径. Linux虚拟目录中比较复杂的部分是它如何来协调管理各个存储设备.Linu ...
- 用java程序模拟网站的登录以及文件批量上传
import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; ...
- mysql与java的之间的连接
package cn.hncu; //注意,以下都是sun公司的接口(类)---这样以后换成Oracle等其它数据库,代码不用动import java.sql.Connection;import ja ...