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 ;
}

最新文章

  1. 适配器模式/adapter模式/结构型模式
  2. VS联调多个解决方案的项目
  3. [Chapter 3 Process]Practice 3.4 Describe what happens when a context switch occurs if the new context is already loaded into one of the register sets.
  4. Android 4.4 音量调节流程分析(二)
  5. 很棒的jQuery代码片段分享
  6. 【转】 android 4.4 Step Counter Sensor计步器的使用
  7. SQL子句执行顺序和Join的一点总结
  8. CentOS Apache服务器安装与配置
  9. 关于Android 7.0无法进行https抓包的问题
  10. security cookie 机制(2)--- 初始化___security_cookie
  11. js数组中两个有相同删除一个
  12. 设置服务器的MySQL允许远程访问/外网访问
  13. 5、Python-字典
  14. ubuntu上zip格式解压乱码解决
  15. Python基础爬虫
  16. excel中如何将时间戳转换为日期格式
  17. Cocoa Touch(二):数据存储CoreData, NSKeyArchiver, NSOutputStream, NSUserDefaults
  18. html 中的列表
  19. Nginx+keepalived 脚本安装主从双机热备自动切换解决方案
  20. [Z] 关于Python Tornado的一些资料

热门文章

  1. Linux安装技巧--安装Uuntu与windows8/10共存
  2. OpenJudge_2757:最长上升子序列
  3. 使用docker搭建gitlab 服务器
  4. (一) Docker in Docker
  5. Web框架_MVC vs MVT
  6. BI结构图及自动建表结构图
  7. 检查bug
  8. 使用Spring AOP切面解决数据库读写分离
  9. OpenCV2:第八章 视频操作
  10. 生产环境屏蔽swagger(动态组装bean)