-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path1226Substrings.cpp
More file actions
41 lines (41 loc) · 828 Bytes
/
1226Substrings.cpp
File metadata and controls
41 lines (41 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char words[100][120];
char sub[120];
char rev[120];
int n;
int check(int s,int t)
{
for(int i=0;i<t-s;i++)
sub[i]=rev[t-s-1-i]=words[0][s+i];
sub[t-s]=rev[t-s]='\0';
//cout<<sub<<endl;
for(int i=0;i<n;i++)
if(!strstr(words[i],sub) &&!strstr(words[i],rev)) return 0;
return 1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%s",words[i]);
int len=strlen(words[0]);
int i;
for(i=len;i>=1;i--)
{
for(int j=0;j+i-1<len;j++)
if(check(j,j+i)) goto success;
}
printf("0\n");
continue;
success:
printf("%d\n",i);
}
return 0;
}