http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=610&pid=1002
#include <stdio.h> #include <string.h> char s[101],con[]="anniversary"; int main() { int T,n,m,len,f; scanf("%d",&T); while(T--) { scanf("%s",s); len=strlen(s); f=0; for(int i=1; i<=9; i++) { int k=0,pos; while(k<len&&strncmp(con,s+k,i)!=0) { k++; } if(k==len) { break; } k+=i; pos=k; for(int j=1; j<=10-i; j++) { k=pos; while(k<len&&strncmp(con+i,s+k,j)!=0) { k++; } if(k==len) { break; } k+=j; while(k<len&&strncmp(con+i+j,s+k,11-(i+j))!=0) { k++; } if(k!=len) { f=1; break; } } if(f==1) { break; } } if(f==0) { printf("NO\n"); } else { printf("YES\n"); } } return 0; }