Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can even write poetic code. Some poems has a strict rhyme scheme like "ABABA" or "ABABCAB". For example, "niconiconi" is composed of a rhyme scheme "ABABA" with A = "ni" and B = "co".

More technically, we call a poem pretty if it can be decomposed into one of the following rhyme scheme: "ABABA" or "ABABCAB". The symbol A, B and C are different continuous non-empty substrings of the poem. By the way, punctuation characters should be ignored when considering the rhyme scheme.

You are given a line of poem, please determine whether it is pretty or not.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

There is a line of poem S (1 <= length(S) <= 50). S will only contains alphabet characters or punctuation characters.

Output

For each test case, output "Yes" if the poem is pretty, or "No" if not.

Sample Input

3
niconiconi~
pettan,pettan,tsurupettan
wafuwafu

Sample Output

Yes
Yes
No
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<limits.h>
#include<algorithm>
#define LL long long
#define mod 1e9 + 7 using namespace std; const int M = ; char a[M];
char s[M];
char A[M];
char B[M];
char C[M]; int main()
{
int t;
cin >> t;
getchar();
while( t-- )
{
gets(s);
int temp = ;
memset(a,'\0',sizeof(a));
for(int i = ; i < strlen(s); ++i)
if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
a[temp++] = s[i];
int len = strlen(a);
int ans = ;
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
if( * i + j * != len)
continue;
memset(A,'\0',sizeof(A));
memset(B,'\0',sizeof(B));
memset(C,'\0',sizeof(C));
strncpy(A,a,i);
strncpy(B,a + i + j,i);
strncpy(C,a + * i + * j,i);
if(strcmp(A,B) == && strcmp(A,C) == && strcmp(B,C) == )
{
memset(A,'\0',sizeof(A));
memset(B,'\0',sizeof(B));
strncpy(A,a + i,j);
strncpy(B,a + * i + j,j);
if(strcmp(A,B) == && strcmp(A,C) != )
{
ans = ;
break;
}
}
}
if(ans)
break;
}
for(int i = ; i < ; ++i)
{
if( * i >= len)
break;
memset(A,'\0',sizeof(A));
memset(B,'\0',sizeof(B));
memset(C,'\0',sizeof(C));
strncpy(A,a,i);
strncpy(B,a + i,i);
strncpy(C,a + len - i,i);
if(strcmp(A,B) == && strcmp(A,C) == && strcmp(B,C) == )
{
for(int j = ; j < i; ++j)
{
memset(A,'\0',sizeof(A));
memset(B,'\0',sizeof(B));
memset(C,'\0',sizeof(C));
strncpy(A,a,j);
strncpy(B,a + j,i - j);
strncpy(C,a + * i,len - * i);
if(strcmp(A,B) != && strcmp(A,C) != && strcmp(B,C) != )
{
ans = ;
break;
}
}
}
if(ans)
break;
}
if(ans)
puts("Yes");
else
puts("No");
}
return ;
}

Pretty Poem的更多相关文章

  1. 2795: [Poi2012]A Horrible Poem

    2795: [Poi2012]A Horrible Poem Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 484  Solved: 235[Subm ...

  2. [BZOJ2795][Poi2012]A Horrible Poem

    2795: [Poi2012]A Horrible Poem Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 261  Solved: 150[Subm ...

  3. ZOJ 3810 Pretty Poem 分类: ACM 2015-05-17 14:40 83人阅读 评论(0) 收藏

    Pretty Poem Time Limit: 2 Seconds     Memory Limit:65536 KB Poetry is a form of literature that uses ...

  4. BZOJ 2795: [Poi2012]A Horrible Poem( hash )

    ...字符串hash. 假如长度x是一个循环节, 那么对于任意n(x | n)也是一个循环节. 设当前询问区间[l, r]长度为len = ∏piai, 最终答案ans = ∏piai' ,我们只需枚 ...

  5. #10038.A Horrible Poem

    #10038.A Horrible Poem 题目传送门 思路解析 既然这道题目在hash板块里,那么自然就可以想到用hash做这道题目. 首先我们可以用hash数组存储字符串的前缀的hash值. 因 ...

  6. P3538 [POI2012]OKR-A Horrible Poem

    P3538 [POI2012]OKR-A Horrible Poem hash+线性筛 题解 <----这篇写的不错(其实是我懒得码字了qwq) UVA10298 Power Strings 的 ...

  7. bzoj 2795 [Poi2012]A Horrible Poem hash+数论

    2795: [Poi2012]A Horrible Poem Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 640  Solved: 322[Subm ...

  8. 洛谷P3538 [POI2012]OKR-A Horrible Poem [字符串hash]

    题目传送门 A Horrible Poem 题目描述 Bytie boy has to learn a fragment of a certain poem by heart. The poem, f ...

  9. 【BZOJ2795】[Poi2012]A Horrible Poem hash

    [BZOJ2795][Poi2012]A Horrible Poem Description 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节.如果字符串B是字符串 ...

随机推荐

  1. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  2. vim 操作

    vim -b test.bin vim 的 -b 选项是告诉 vim 打开的是一个二进制文件,不指定的话,会在后面加上 0x0a ,即一个换行符,这样若是二进制文件,则文件被改变了,后面多了一个0x0 ...

  3. ffmpeg内置aac编码器正式发布

    https://www.ffmpeg.org/#aac_encoder_stable February 15th, 2016, FFmpeg 3.0 "Einstein" FFmp ...

  4. Apache Spark Streaming的优点

    Apache Spark Streaming的优点: (1)优势及特点 1)多范式数据分析管道:能和 Spark 生态系统其他组件融合,实现交互查询和机器学习等多范式组合处理. 2)扩展性:可以运行在 ...

  5. struts2+Hibernate4+spring3+EasyUI环境搭建之四:引入hibernate4以及spring3与hibernate4整合

    1.导入hibernate4 jar包:注意之前引入的struts2需要排除javassist  否则冲突 <!-- hibernate4 --> <dependency> & ...

  6. ASP.NET项目中引用全局dll

    在ASP.NET项目中,有些dll是全局dll,也就是说,没有放在单个项目的引用中.它们一般存放在如下目录C:\Windows\assembly中 这个时候,我们需要在单个项目中引用他们,应该如何做呢 ...

  7. 前端的一些常用DOM和事件归纳

    1.document.getElementById(id); document.getElementByTagName(tagName);       document.getElementsByNa ...

  8. angular 管理后台

    http://blog.csdn.net/iamnieo/article/details/50474399

  9. C语言简单实现sizeof功能代码

    sizeof不是函数,而是运算符,C/C++语言编译器在预编译阶段的时候就已经处理完了sizeof的问题,也就是说sizeof类似于宏定义. 下面给出一个sizeof的一个宏定义实现版本 #defin ...

  10. servler--请求重定向

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...