题意:要求在一个字符串中找出三段,然后能拼成一个固定的单词,问是否可行

BC周年庆第二题,我枚举了那个单词的切断位置,然后到给的字符串里分别找,然后就没有然后了```

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 #include<math.h>
 5 using namespace std;
 6 
 7 char s[105];
 8 char t[15]=" anniversary";
 9 int l=0;
10 
11 bool check(int a,int b){
12     int pos=1,p=1;
13     int i,j;
14     bool f1=0,f2=0,f3=0;
15     for(i=1;i<=l;i++){
16         if(!f1){
17             if(s[i]==t[1]){
18                 int pos=1;
19                 bool f=1;
20                 for(pos=1;pos<=a&&f;pos++){
21                     if(s[i+pos-1]!=t[pos])f=0;
22                 }
23                 if(f){
24                     f1=1;
25                     i=i+pos-2;
26                 }
27             }
28         }
29         else if(!f2){
30             if(s[i]==t[a+1]){
31                 int pos=a+1;
32                 bool f=1;
33                 for(pos=a+1;pos<=b&&f;pos++){
34                     if(s[i+pos-a-1]!=t[pos])f=0;
35                 }
36                 if(f){
37                     f2=1;
38                     i=i+pos-a-2;
39                 }
40             }
41         }
42         else if(!f3){
43             if(s[i]==t[b+1]){
44                 int pos=b+1;
45                 bool f=1;
46                 for(pos=b+1;pos<=11&&f;pos++){
47                     if(s[i+pos-b-1]!=t[pos])f=0;
48                 }
49                 if(f)return 1;
50             }
51         }
52     }
53     return 0;
54 }
55 
56 int main(){
57     int T;
58     scanf("%d",&T);
59     while(T--){
60         scanf("%s",s+1);
61         l=strlen(s+1);
62         int i,j;
63         bool f=1;
64         for(i=1;i<10&&f;i++){
65             for(j=i+1;j<=10&&f;j++){
66                 if(check(i,j)==1){
67                     f=0;
68                 }
69             }
70         }
71         if(!f)printf("YES\n");
72         else printf("NO\n");
73     }
74     return 0;
75 }
View Code