Hidden String
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string ss of length nn. He wants to find three nonoverlapping substrings s[l_1..r_1]s[l1..r1], s[l_2..r_2]s[l2..r2], s[l_3..r_3]s[l3..r3] that:
-
1 le l_1 le r_1 < l_2 le r_2 < l_3 le r_3 le n1≤l1≤r1<l2≤r2<l3≤r3≤n
-
The concatenation of s[l_1..r_1]s[l1..r1], s[l_2..r_2]s[l2..r2], s[l_3..r_3]s[l3..r3] is "anniversary".
There are multiple test cases. The first line of input contains an integer TT (1 le T le 100)(1≤T≤100), indicating the number of test cases. For each test case:
There's a line containing a string ss (1 le |s| le 100)(1≤∣s∣≤100) consisting of lowercase English letters.
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
2 annivddfdersewwefary nniversarya
YES NO
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include <stdio.h> 2 #include <string.h> 3 4 char a[105],compare[15]={"anniversary"}; 5 int main() 6 { 7 int T; 8 int flg; 9 int n,i,j,k,x,y,z,h,h2; 10 scanf("%d",&T); 11 while(T--) 12 { 13 flg=0; 14 scanf("%s",a); 15 n=strlen(a); 16 int c=0; 17 for(i=0;i<n;i++) 18 { 19 if(flg==1) 20 break; 21 if(a[i]==compare[0] && c<=10) 22 { 23 // printf("hi x%d ",i); 24 x=i,c=0; 25 while(a[x]==compare[c] && c<=10) 26 { 27 // printf("C:%d ",c); 28 if(c==10) 29 { 30 flg=1; 31 break; 32 } 33 c++,x++; 34 } 35 for(j=x+1;j<n;j++) 36 { 37 if(flg==1) 38 break; 39 if(a[j]==compare[c] && c<=10) 40 { 41 h=c; 42 // printf("hi y%d ",j); 43 y=j; 44 while(a[y]==compare[c] && c<=10) 45 { 46 // printf("C:%d ",c); 47 if(c==10) 48 { 49 flg=1; 50 break; 51 } 52 c++,y++; 53 } 54 for(k=y+1;k<n;k++) 55 { 56 if(flg==1) 57 break; 58 if(a[k]==compare[c] && c<=10) 59 { 60 h2=c; 61 // printf("hi z%d ",k); 62 z=k; 63 while(a[z]==compare[c] && c<=10) 64 { 65 // printf("C:%d ",c); 66 if(c==10) 67 { 68 flg=1; 69 break; 70 } 71 c++,z++; 72 } 73 c=h2; 74 } 75 } 76 c=h; 77 } 78 79 } 80 } 81 } 82 if(flg==1) 83 printf("YES "); 84 else 85 printf("NO "); 86 } 87 return 0; 88 }