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. 数往知来C#之面向对象准备〈一〉

    1.CLR加载编译源文件 注1.:当你点击调试或者生成解决方案的时候这就是一个编译过程首先CLR加载源文件也就是你写的代码(此代码在文件中是字符串)然后将项目中的嗲吗编译成IL代码进而生成程序集 证明 ...

  2. bzoj 2095: [Poi2010]Bridges(二分法+混合图的欧拉回路)

    [题意] 给定n点m边的无向图,对于边u,v,从u到v边权为c,从v到u的边权为d,问能够经过每条边一次且仅一次,且最大权值最小的欧拉回路. [思路] 二分答案mid,然后切断权值大于mid的边,原图 ...

  3. Hive1.3 JDBC连接-代码片段

    package com.hive.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Re ...

  4. linux appear packet loss solution

    故障排查: 早上突然收到nagios服务器check_icmp的报警,报警显示一台网站服务器的内网网络有问题.因为那台服务器挂载了内网的NFS,因此内网的网络就采用nagios的check_icmp来 ...

  5. Homework-10 the Enhanced Version

    经过一周对于JavaScript HTML语言等相关知识的学习,我终于基本完成了作业的要求,也是实现了我原先计划的第二部,推出了加强版的Homework-10 他由3个HTML组成,JS脚本直接选择嵌 ...

  6. HDU 5831 Rikka with Parenthesis II (栈+模拟)

    Rikka with Parenthesis II 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5831 Description As we kno ...

  7. 使用truss、strace或ltrace诊断软件的“疑难杂症”

    简介 进程无法启动,软件运行速度突然变慢,程序的"Segment Fault"等等都是让每个Unix系统用户头痛的问题,本文通过三个实际案例演示如何使用truss.strace和l ...

  8. POJ 3169 Layout (spfa+差分约束)

    题目链接:http://poj.org/problem?id=3169 差分约束的解释:http://www.cnblogs.com/void/archive/2011/08/26/2153928.h ...

  9. 学习LINQ,发现一个好的工具。LINQPad!!

    今日学习LINQ,发现一个好的工具.LINQPad!! 此工具的好处在于,不需要在程序内执行,直接只用工具测试.然后代码通过即可,速度快,简洁方便. 可以生成其LINQ查询对应的lambda和SQL语 ...

  10. 简单的玩玩etimer <contiki学习笔记之九>

    好吧,我承认etimer有点小复杂,主要是它似乎和contiki的process搅在一起,到处都在call_process.那就先搜搜contiki下的etimer的example看看,然后再试着写一 ...