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. 使用jQuery Mobile实现通讯录

    jQuery Mobile 通讯录 拨打电话作者:方倍工作室 地址: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional/ ...

  2. HDU 5762 Teacher Bo (暴力)

    Teacher Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...

  3. eclipse中如何设置tomcat启动时间

    现象:在eclipse中启动tomcat总是提示“Server Tomcat v5.5 Server @ localhost was unable to start within 45 seconds ...

  4. display:none;与visibility:hidden;的区别

    visibility:隐藏对应的元素但不挤占该元素原来的空间.display:隐藏对应的元素并且挤占该元素原来的空间. 下面来看visibility和dispaly的一些参数 visibility用来 ...

  5. poj 3268 Silver Cow Party(最短路)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17017   Accepted: 7767 ...

  6. POJ1228(稳定凸包问题)

    题目:Grandpa's Estate   题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...

  7. VMware搭建12.0搭建Mac OS10.11详细过程

    1.软件准备 1.1VMware12.0 1.2VMware增强包 1.3Mac OS10.11 cdr(相当于dmg) 1.4securable.exe 2.软件破解 2.1VMware输入序列号破 ...

  8. 浅析网站开发中的 meta 标签的作用

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  9. Visifire的一些使用心得

    1.如何让图表的Y轴不从0开始显示:有时一系列的数据差别很小,如果从0开始显示,在Y轴上,会一堆数据都堆在某一个区间.例如期货的蜡烛图.将ViewportRangeEnabled设为true即可解决此 ...

  10. 十,选择cfee编辑器并学会调试程序。以及结束语。

    为什么推荐用cfree呢?因为我认为这个编辑器界面友好,用起来方便. 你也许会问,调试程序是什么? 那么下面思考几个问题:对于前面讲的分支结构和循环结构有点不懂怎么办?如果写的程序语法没有错误但是运算 ...