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 题目大意:
给你n个字符串 要你找这n个字符串中最大的相同字串(字符串可以逆置) 分析:
先找到最小的母串 然后这个母串的所有字串从大到小 都和n个串循环一遍 只要找到符合的答案就跳出
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#define N 220
#define INF 0xffffffff
using namespace std; int main()
{
int T,n;
char str[N][N],s1[N],s2[N];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int Min=INF,b;
for(int i=; i<n; i++)
{
scanf("%s",str[i]);
if(strlen(str[i])<Min)
{
Min=strlen(str[i]);
b=i;
}
}
int len=Min,flag;
while(len)
{
for(int i=; i<=Min-len; i++)
{
flag=;
strncpy(s1,str[b]+i,len);
int k=;
for(int i=len-; i>=; i--)
{
s2[k++]=s1[i];
}
s1[len]=s2[len]='\0';
for(int i=; i<n; i++)
{
if(strstr(str[i],s1)==NULL && strstr(str[i],s2)==NULL)
{
flag=;
break;
}
}
if(flag==)
{
break;
}
}
if(flag==)
break;
len--;
}
printf("%d\n",len);
}
return ;
}

Substrings--poj1226(字符串)的更多相关文章

  1. Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重

    #1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the nu ...

  3. Substrings 子字符串-----搜索

    Description You are given a number of case-sensitive strings of alphabetic characters, find the larg ...

  4. Ruby:字符串处理函数

    字符串处理函数1.返回字符串的长度 str.length => integer 2.判断字符串中是否包含另一个串 str.include? other_str => true or fal ...

  5. Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

    http://blog.csdn.net/rowanhaoa/article/details/38116713 A:Game With Sticks 水题.. . 每次操作,都会拿走一个横行,一个竖行 ...

  6. 2019NC#1

    LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...

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

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

  8. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  9. LA4671 K-neighbor substrings(FFT + 字符串Hash)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...

  10. 字符串(后缀数组):POJ 3415 Common Substrings

    Common Substrings   Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤ ...

随机推荐

  1. js toString() 方法 Number() 方法 等 类型转换

    1.1 数字类型转字符串 String() 变量.toString() toString() 方法 toString() 方法可把一个逻辑值转换为字符串,并返回结果. 1.2 字符串转数字类型 Num ...

  2. 旅行商问题——状态压缩DP

    问题简介 有n个城市,每个城市间均有道路,一个推销员要从某个城市出发,到其余的n-1个城市一次且仅且一次,然后回到再回到出发点.问销售员应如何经过这些城市是他所走的路线最短? 用图论的语言描述就是:给 ...

  3. aaaaa

    svn://192.168.199.182/anti-counterfeiting/trunk svn://192.168.199.182/anti-ds/trunk/antifake-service ...

  4. Codeforces Round #555 (Div. 3) 解题报告

    A.Reachable Numbers 题意: 给定操作f(x):将x加1,删去得到的数的所有末尾0,如f(10099)=10099+1=10100→1010→101.现在给定一个数n,对n进行无限次 ...

  5. 【2019.6.2】python:json操作、函数、集合、random()等

    一.json操作: json就是一个字符串,从文件中读取json,必须是json格式.j'son串中必须是双引号,不能有单引号,单引号不能转换 1.1使用: import json #使用json先引 ...

  6. Day01:我的Python学习之路

    1.Python是什么语言? Python是动态的解释性的强类型定义的语言. (1)动态语言与静态语言 ①静态语言:在编译期间就会去做数据类型检查的语言,如C,C++. ②动态语言:在运行期间才会去做 ...

  7. python中的参数、全局变量及局部变量

    1.位置参数.关键字参数.默认参数的使用 位置参数.关键字参数 def test(x,y,z): print(x) print(y) print(z) test(1,2,3) #位置参数,必须一一对应 ...

  8. Centos7中 mysql5.7 用户 创建 、授权、远程登录

    1.添加用户跟以往版本不同,MySQL5.7 mysql.user表没有password字段,这个字段改成了 authentication_string:这里我们使用命令进行创建用户:  CREATE ...

  9. Linux 之 nano 编辑器的使用

    在Linux操作系统中,有很多的文本编辑器,最为重要的就是vi文本编辑器,下面来介绍一个简单的nano文本编辑器.nano的使用简单,我们可以直接加上文件名就能够打开一个旧文件或新文件,我们可以打开一 ...

  10. 测试网站链接是否可用(wget和curl)

    一.wget用法案例 系统给的命令参数如下: [root@litong_centos mysql3307]# wget --help GNU Wget 1.14, a non-interactive ...