首页 > 其他分享 >HDU 1238 Substrings

HDU 1238 Substrings

时间:2023-02-20 16:38:53浏览次数:60  
标签:HDU min str2 str1 1238 pos len Substrings ans


Substrings


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7699    Accepted Submission(s): 3474

Problem 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 file 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<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define N 101
char a[N][N];
int main()
{
int t,n,min,k,i,j,len,pos,z,f,ans;
// freopen("text.txt","r",stdin);
scanf("%d",&t);getchar();
while(t--)
{
scanf("%d",&n);
min=101;
for(i=0;i<n;i++)
{
scanf("%s",a[i]);
len=strlen(a[i]);
if(len<min)
{
min=len;
pos=i;
}
}
len=min;
char str1[N],str2[N];
ans=0;
for(i=0;i<len;i++)
{
for(j=i;j<len;j++)
{
z=0;
for(k=i;k<=j;k++)
{
str1[z++]=a[pos][k];
str2[j-k]=a[pos][k];
}
str1[z]='\0';
str2[j-i+1]='\0';
f=1;
for(k=0;k<n;k++)
{
if(!strstr(a[k],str1)&&!strstr(a[k],str2))
{
f=0;
break;
}
}
k=strlen(str1);
if(f==1&&ans<k)
{
ans=k;
}
}
}
printf("%d\n",ans);
}
return 0;
}




标签:HDU,min,str2,str1,1238,pos,len,Substrings,ans
From: https://blog.51cto.com/u_1382267/6068680

相关文章

  • HDU 1256 画8
    画8TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):4645    AcceptedSubmission(s):2004Proble......
  • HDU 1219 AC Me
    ACMeTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):13482    AcceptedSubmission(s):5934Pro......
  • HDOJ2111 Saving HDU(背包问题)
    题目链接:​​SavingHDU​​这题是个背包问题,首先按照单价排序,然后,装的下就装,装不下就分割。importjava.util.Scanner;//背包问题publicclassMain{privatestaticScan......
  • Bone Collector HDU - 2602【 01 背包 】
    BoneCollector HDU-2602 &:自己的动态规划好差的,算法也跟不上,真是处处碰壁。于是找点简单的题看看,散散心。背包是比较典型的题了,看了好一会的背包九讲,对比着来学......
  • 畅通工程续(HDU 1874)(简单最短路)
    某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的......
  • dp HDU - 5074
    按题意推表达式#include<cstdio>#include<cstring>#definemax(a,b)(a)>(b)?(a):(b)intdp[105][105],num[105][105],a[105];intmain(){intt;sca......
  • C - Cake HDU - 1722 (数学)
    题意:就是一个蛋糕,被分成n或者m份。问最少动几刀。看一下这个图,就知道公式了,n+m-gcd(n,m);#include<cstdio>#include<iostream>usingnamespacestd;#definelllon......
  • C - Cake HDU - 1722 (数学)
    题意:就是一个蛋糕,被分成n或者m份。问最少动几刀。看一下这个图,就知道公式了,n+m-gcd(n,m);#include<cstdio>#include<iostream>usingnamespacestd;#definelllon......
  • HDU 4507 (数位dp)
    HDU4507(数位dp)题意一个数满足以下三个条件之一,则被认为与7有关。1、整数中某一位是7;2、整数的每一位加起来的和是7的整数倍;3、这个整数是7的整数倍;求区间[L,R]内......
  • HDU 3709 数位dp
    HDU3709(数位dp)题意求区间[L,R]内满足以下性质的数:选定该数的一个位置,左右两边的力矩相等,如4139,选取'3'这位,左边4×2+1×1=9×1.思路一开始想着枚举每个点来做,......