Substrings
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 13348   Accepted: 4722

Description

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.

Input

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.

Output

There should be one line per test case containing the length of the largest string found.

Sample Input

2
3
ABCD
BCDFF
BRCD
2
rose
orchid

Sample Output

2
2
直接暴力枚举。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[][];
int n;
int solve()
{
char sub[];
char rsub[];
int len=strlen(s[]);
int cnt=;
for(int l=len;l>;l--)
{
for(int x=;x+l<=len;x++)
{
memset(sub,,sizeof(sub));
memset(rsub,,sizeof(rsub));
strncpy(sub,s[]+x,l);
strcpy(rsub,sub);
reverse(rsub,rsub+strlen(rsub));
cnt=;
for(int i=;i<n;i++)
{
if(strstr(s[i],sub)!=NULL||strstr(s[i],rsub)!=NULL)
{
cnt++;
}
else break;
}
if(cnt==n-) return strlen(sub);
}
}
return ;
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
memset(s,,sizeof(s));
for(int i=;i<n;i++)
{
scanf("%s",s[i]);
}
printf("%d\n",solve());
}
return ;
}

POJ1226(strstr)的更多相关文章

  1. POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串

    题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS   Memory Limit: 10000K Total ...

  2. [PHP源码阅读]strpos、strstr和stripos、stristr函数

    我在github有对PHP源码更详细的注解.感兴趣的可以围观一下,给个star.PHP5.4源码注解.可以通过commit记录查看已添加的注解. strpos mixed strpos ( strin ...

  3. [LeetCode] Implement strStr() 实现strStr()函数

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  4. strstr 函数的实现

    strstr函数:返回主串中子字符串的位置后的所有字符. #include <stdio.h> const char *my_strstr(const char *str, const c ...

  5. 28. Implement strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  6. Leetcode 详解(Implement strstr)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  7. LintCode StrStr

    1. 讨论目标字符串若为空, 则返回-1: 资源字符串若为空, 则返回-1. 2.讨论目标字符串个数为零, 则返回0: 资源字符串个数为零, 则返回-1. 3. 插入旗帜来使第二循环的结束为有条件地返 ...

  8. strstr函数

    原型:char * strstr( char *haystack,  char *needle ) 用法:#include <string.h> 功能:在haystack中寻找needle ...

  9. strstr函数的用法

    C语言函数 编辑 包含文件:string.h 函数名: strstr 函数原型:      extern char *strstr(char *str1, const char *str2); 语法: ...

随机推荐

  1. HDU 4635 Strongly connected(强连通)经典

    Strongly connected Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. Android——动画的分类

    Android包含三种动画:View Animation, Drawable Animation, Property Animation(Android 3.0新引入). 1.View Animati ...

  3. Android加壳native实现

    本例仅在Android2.3模拟器跑通过,假设要适配其它机型.请自行研究,这里不过抛砖引玉. 0x00 在Android中的Apk的加固(加壳)原理解析和实现,一文中脱壳代码都写在了java层非常ea ...

  4. ubuntu + lamp + laravel 环境配置

    首先是LAMP 安装顺序是 A(Apache服务器)  M(Mysql) P(Php) 安装apache sudo apt-get install apache2 安装mysql sudo apt-g ...

  5. python訪问redis

    python訪问redis 1 Linux上安装redis a) 下载 $ wget http://download.redis.io/releases/redis-3.0.5.tar.gz b) 编 ...

  6. ScrollView滑动的监听

    ScrollView滑动的监听 有时候我们须要监听ScrollView的滑动事件.来完毕业务需求. 第一种: 能够直接实现OnTouchListener接口.在这里面写你所须要的操作 scrollVi ...

  7. 不使用flash实现复制文字(图片)到剪贴板

    <div>这里是待复制的文字或图片</div> var range = document.createRange(); var referenceNode = document ...

  8. ThinkPHP5 安装自定义模块

    安装官方给的demo,在build.php文件中 <?php // +-------------------------------------------------------------- ...

  9. Mac终端基本指令,一些实用命令的收集.

    基本命令1.列出文件ls 参数 目录名        例: 看看驱动目录下有什么:ls /System/Library/Extensions参数 -w 显示中文,-l 详细信息, -a 包括隐藏文件 ...

  10. CMTime 与 CMTimeMakeWithSeconds

    1.首先先看代码,这段代码的作用就是要让视频播放区域有个封面.不会显的太空当. - (void)avPlayerDidPlayed:(NSNotification *)noti { [_avPlaye ...