BestCoder 1st Anniversary ($) 1002 Hidden String

Hidden String

 
 Accepts: 437
 
 Submissions: 2174
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 262144/262144 K (Java/Others)
Problem Description

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. 1 \le l_1 \le r_1 < l_2 \le r_2 < l_3 \le r_3 \le n1l1​​r1​​<l2​​r2​​<l3​​r3​​n

  2. 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".

Input

There are multiple test cases. The first line of input contains an integer T(1 \le T \le 100)(1T100), indicating the number of test cases. For each test case:

There's a line containing a string s(1 \le |s| \le 100)(1s100) consisting of lowercase English letters.

Output

For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

Sample Input
2
annivddfdersewwefary
nniversarya
Sample Output
YES
NO

 

 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\n",i);
24                 x=i,c=0;
25                 while(a[x]==compare[c] && c<=10)
26                 {
27                     // printf("C:%d\n",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\n",j);
43                         y=j;
44                         while(a[y]==compare[c] && c<=10)
45                         {
46                             // printf("C:%d\n",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\n",k);
62                                 z=k;
63                                 while(a[z]==compare[c] && c<=10)
64                                 {
65                                     // printf("C:%d\n",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\n");
84         else
85             printf("NO\n");
86     }
87     return 0;
88 }
View Code

 

posted @ 2015-08-30 18:52  cyd2014  阅读(197)  评论(0编辑  收藏  举报