ZOJ 3818 Pretty Poem
来源:互联网 发布:php源码解密工具 编辑:程序博客网 时间:2024/06/05 10:31
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
3niconiconi~pettan,pettan,tsurupettanwafuwafu
Sample Output
YesYesNo
Author: JIANG, Kai
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <stdexcept>#include <functional>#include <utility>#include <ctime>using namespace std;#define PB push_back#define MP make_pair#define REP(i,n) for(int i=0;i<(n);++i)#define FOR(i,l,h) for(int i=(l);i<=(h);++i)#define DWN(i,h,l) for(int i=(h);i>=(l);--i)#define CLR(vis,pos) memset(vis,pos,sizeof(vis))#define PI acos(-1.0)#define INF 0x7FFFFFFF#define LINF 1000000000000000000LL#define eps 1e-8typedef long long ll;const int maxn=55;char s[maxn];int main(){ int cas_t; cin>>cas_t; while(cas_t--) { scanf("%s",s); int len,alen,blen; len=strlen(s); int j=0; REP(i,len) if( (s[i]>='a'&&s[i]<='z') || (s[i]>='A'&&s[i]<='Z') ) s[j++]=s[i]; len=j; bool flag=false; char s1[maxn],s2[maxn],s3[maxn],a[maxn],b[maxn],c[maxn]; for(int i=0;i*2<len;i++) { //ABABA alen=len-i*2; blen=i-alen; if(alen<i) { REP(j,alen) a[j]=s[j];a[alen]=0; //A memcpy(b,&s[alen],blen),b[blen]=0; //B memcpy(c,&s[2*i],alen),c[alen]=0; //A memcpy(s1,s,i),s1[i]=0; //AB memcpy(s2,&s[i],i),s2[i]=0; //AB if(strcmp(s1,s2)==0 && strcmp(a,c)==0 && strcmp(a,b)!=0) { flag=true; break; } } //ABABCAB if(i*3<len && !flag) { FOR(alen,1,i-1) { blen=i-alen; REP(j,alen) a[j]=s[j];a[alen]=0; //A memcpy(b,&s[alen],blen),b[blen]=0; //B memcpy(s1,s,i),s1[i]=0; //AB memcpy(s2,&s[i],i),s2[i]=0; //AB memcpy(s3,&s[len-i],i),s3[i]=0;//AB memcpy(c,&s[2*i],len-3*i),c[len-3*i]=0; if(strcmp(s1,s2)==0 && strcmp(s1,s3)==0 && strcmp(a,b)!=0 && strcmp(a,c)!=0 && strcmp(b,c)!=0) { flag=true; break; } } } } if(flag) puts("Yes"); else puts("No"); } return 0;}
- ZOJ - 3818 Pretty Poem
- zoj 3818 Pretty Poem
- ZOJ 3818 Pretty Poem
- zoj 3818 Pretty Poem
- ZOJ 3818 Pretty Poem
- ZOJ 3818 Pretty Poem 字符串
- ZOJ 3818 Pretty Poem 字符串
- zoj 3818 Pretty Poem(模拟)
- ZOJ - 3818 Pretty Poem 暴力
- ZOJ 3818 Pretty Poem 模拟题
- ZOJ 3818 Pretty Poem(模拟题)
- zoj 3818 Pretty Poem (模拟)
- zoj 3818 Pretty Poem(暴力枚举)
- 模拟 之 zoj 3818 Pretty Poem
- ZOJ 3818 Pretty Poem(暴力求解)
- ZOJ Problem Set - 3818 Pretty Poem
- zoj 3831 Pretty Poem
- ZOJ 3810 Pretty Poem
- linux定时任务的设置
- sql exists 用法
- Android px转dip px转sp法则
- js 中几种简化编写方式
- Hive学习之连接查询
- ZOJ 3818 Pretty Poem
- boost在linux下编译
- c中scanf与gets区别
- 使用wxPython开发一个简单GUI应用
- HDOJ 题目1150 Machine Schedule(二分图最小点覆盖)
- js 的模块化的几种用法和方式
- Windows Phone Toolkit-- DatePicker
- IOS valid architectures
- 左外连接、右外连接、内连接、全连接