标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 368 Accepted Submission(s): 143
/** 题意:给你一个串,看是否存在“anniversary”,并且是分成三段的 做法:暴力 **/ #include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <string.h> #define maxn 1010 + 10 using namespace std; char c[120] = {"anniversary"}; __int64 index = 0; char ch[maxn]; int solve(int tt,int len) { __int64 res = 0; __int64 mmax = 0; __int64 tmp = 0; for(int i=tt;i<len;i++) { if(ch[i] == c[index]) { int j; res = 0; for(j=0;;j++) { if(ch[i+j] == c[index+j] && i+j<len) { res++; } else break; } if(res > mmax) { mmax = res; tmp = i + mmax; } } } index += mmax; return tmp; } int main() { //freopen("in.txt","r",stdin); int T; scanf("%d",&T); while(T--) { index = 0; scanf("%s",ch); __int64 len = strlen(ch); __int64 tt = 0; tt = solve(0,len); if(strcmp(ch,c) == 0) { printf("YES\n"); continue; } if(tt == 0) { printf("NO\n"); continue; } else if(index == 11) { printf("YES\n"); continue; } tt = solve(tt,len); if(tt == 0) { printf("NO\n"); continue; } else if(index == 11) { printf("YES\n"); continue; } tt = solve(tt,len); if(tt == 0) { printf("NO\n"); continue; } if(index == 11) printf("YES\n"); else printf("NO\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenyang920/p/4677280.html