码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder 1st Anniversary ($) 1002 Hidden String

时间:2015-08-30 19:27:19      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

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[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2??], s[l_3..r_3]s[l?3??..r?3??] that:

  1. 1 \le l_1 \le r_1 < l_2 \le r_2 < l_3 \le r_3 \le n1l?1??r?1??<l?2??r?2??<l?3??r?3??n

  2. The concatenation of s[l_1..r_1]s[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2??], s[l_3..r_3]s[l?3??..r?3??] 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

 

BestCoder 1st Anniversary ($) 1002 Hidden String

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!