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. [HIve - LanguageManual] Sort/Distribute/Cluster/Order By

    Syntax of Order By Syntax of Sort By Difference between Sort By and Order By Setting Types for Sort ...

  2. append some buttons to the standard datagrid pager bar

    <script type="text/javascript">  $(function(){   var pager = $('#dg').datagrid('getP ...

  3. Hibernate、Mybatis 通过数据库表反向生成java类和配置

    一.通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件    (转载孙宇老师的文章) 二.Mybatis生成实体类和配置文件: myeclipse下生 ...

  4. ocp 1Z0-043 1-60题解析

    1.You observe that a database performance has degraded overa period of time. While investigating the ...

  5. animate平滑回到顶部

    Js: //回到顶部 $(".totop").click(function () { $("body,html").animate({scrollTop: 0} ...

  6. HttpWebRequest和HttpWebResponse用法小结

    http://www.cnblogs.com/willpan/archive/2011/09/26/2176475.html http://www.cnblogs.com/lip0121/p/4539 ...

  7. JAVA事务的概念

    From:http://www.cnblogs.com/kristain/articles/2038397.html 一.什么是事务 事务是访问数据库的一个操作序列,数据库应用系统通过事务集来完成对数 ...

  8. CSS 文本格式

    整理自:(http://www.w3school.com.cn/css/css_text.asp) Text Color 颜色属性被用来设置文字的颜色. 颜色是通过CSS最经常的指定: 十六进制值 - ...

  9. Usage of readonly and const

    Many new learners can not make sure the usage scenarios of readonly and const keywords. In my opinio ...

  10. apache 限制IP网段访问

    <Directory "地址.."> Options Indexes FollowSymLinks MultiViews AllowOverride None Orde ...