My approach is to split the string (anniversary) into three segments. Enumerate all the cases, and there are more than 100 kinds of looks.
In each case, you can determine if the three strings are found in the input string and do not intersect.
O (︶^︶) o Alas, the idea soon has, the code is ugly, looking for the wrong half a day, the final on-court 1 A.
Write a problem when cerebral palsy, also engaged a kmp up ... In fact, the length of the string 100, the violence and KMP gap is not very large, it seems to be able to 0ms AC.
According to their own ideas to be able to cross this problem, has been very satisfied with ...
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Chars[ +];Chary[ -]="Anniversary";Charone[ -],two[ -],three[ -];Charr[ +];Const intN =1000002;intNext[n];CharS[n], t[n];intSlen, Tlen;inttot;intFlag;intLenZ;voidGetNext () {intJ, K; J=0; K =-1; next[0] = -1; while(J <Tlen)if(k = =-1|| T[J] = =T[k]) next[++J] = + +K; Elsek=next[k];}intKmp_index () {inti =0, j =0; GetNext (); while(I < Slen && J <Tlen) { if(j = =-1|| S[i] = =T[j]) {i++; J + +; } ElseJ=Next[j]; } if(J = =Tlen)returnITlen; Else return-1;}intMain () {intTT; inti,j,k; scanf ("%d",&TT); while(tt--) {scanf ("%s", s); strcpy (r,s); LenZ=strlen (s); Flag=0; inti,j; for(i=1; i<=Ten; i++) { for(j=i;j<=9; j + +) {strcpy (s,r); intu=0; for(k=0; k<=i-1; k++) one[u]=y[k],u++; One[u]=' /'; U=0; for(k=i;k<=j;k++) two[u]=y[k],u++; Two[u]=' /'; U=0; for(k=j+1;k< One; k++) three[u]=y[k],u++; Three[u]=' /'; U=0; //printf ("%s%s%s\n", one,two,three); if(i==1&&j==2) {strcpy (one,"Anniv"); strcpy (both,"ers"); strcpy (Three,"ary"); } intLenone=strlen (one); intlentwo=strlen (both); intLenthree=strlen (three); strcpy (s,s); strcpy (T,one); Slen=strlen (S); Tlen=strlen (T); intoneshou=Kmp_index (); intII; if(oneshou!=-1) {s[0]=0; Tot=0; LenZ=strlen (s); for(ii=oneshou+lenone;ii<lenz;ii++) S[tot]=s[ii],tot++; S[tot]=' /'; strcpy (T,two); Slen=strlen (S); Tlen=strlen (T); inttwoshou=Kmp_index (); if(twoshou!=-1) {strcpy (s,s); LenZ=strlen (S); Tot=0; s[0]=0; for(ii=twoshou+lentwo;ii<lenz;ii++) S[tot]=s[ii],tot++; S[tot]=' /'; strcpy (T,three); Slen=strlen (S); Tlen=strlen (T); if(Kmp_index ()!=-1) Flag=1; } } if(flag) Break; } if(flag) Break; } if(flag) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
HDU 5311 Hidden String