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. bzoj 1009 [HNOI2008]GT考试(DP+KMP+矩阵乘法)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1009 [题意] 给定一个字符串T,问长度为n且不包含串T的字符串有多少种. [思路] ...

  2. Tkinter教程之Pack篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1813077 '''Tkinter教程之Pack篇'''#Pack为一布局管理器,可将它视为一个 ...

  3. 使用Async同步执行异步函数

    为了适应异步编程,减少回调的嵌套,我在项目中引入了Async,当批量处理且需要同步执行一些逻辑相同的异步函数时,觉得还是Async最为靠谱. 我有一个类似下面代码的场景,依据数组中的每一个元素执行一个 ...

  4. 总结的Ubuntu的若干小知识

    一.默认开机直接进入到Ubuntu命令行界面 安装Ubuntu后,开机会默认进入到图形界面,如果不喜欢图形界面,可以通过修改配置,直接进入命令行界面,还行节省100多兆的内存空间.具体方法如下: 修改 ...

  5. 详解HTTP中的摘要认证机制(转)

    Basic认证方式是存在很多缺陷的,具体表现如下: 1,  Basic认证会通过网络发送用户名和密码,并且是以base64的方式对用户名和密码进行简单的编码后发送的,而base64编码本身非常容易被解 ...

  6. linux高级数据存储

    linux内此存储模式由5部分组成,自低向上的顺序: 物理卷,内核块设备驱动,内核文件系统驱动,虚拟文件系统,应用程序数据结构; 系统中所有的文件仅按此模式存储,无论是数据还是元数据,均在此模式下统一 ...

  7. 查看Linux里某文件的前面/后面几行中的某一行

    如,我想看/etc/profile文件的前5行里的第5行. 则,   head -5 /etc/profile  |  tail -1  管道|啊,很简单,就是把左边命令的结果,作为右边的输入. 如, ...

  8. 有趣的Node爬虫,数据导出成Excel

    最近一直没更新了诶,因为学习Backbone好头痛,别问我为什么不继续AngularJs~因为2.0要出来了啊,妈蛋!好,言归正传,最近帮我的好基友扒数据,他说要一些股票债券的数据.我一听,那不就是要 ...

  9. 通过request读取所有参数

    获取request里的所有参数及参数名(参数名自动获取)  -  [ Java ] request里有两个方法: 1)request.getParameterMap(); Enumeration en ...

  10. 嵌入式LINUX入门到实践(一)

    MINI2440 IIC协议 IIC协议在工程中应用广泛,在我看来,此协议的优势就在于其硬件及其简单,结构清晰. 首先来解读一下S3C2440A这款芯片的IIC协议. 一.一个协议的解读从如上结构图中 ...