ZOJ 3818 Pretty Poem (水题)

ZOJ3818 水题一个。 直接暴力搞。 就是需要注意A,B,C要是不同的。

Pretty Poem

Time Limit: 2 Seconds Memory Limit: 65536 KB

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.


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.


For each test case, output “Yes” if the poem is pretty, or “No” if not.

Sample Input


Sample Output


Author: JIANG, Kai Source: The 2014 ACM-ICPC Asia Mudanjiang Regional First Round

/* ***
Author :kuangbin
Created Time :2014/10/5 9:10:11
File Name :ZOJ3818.cpp
************************************************ */

#include <stdio.h>

#include <string.h>








#include <math.h>

#include <stdlib.h>

#include <time.h>
using namespace std;
bool check1(string str,string A,string B){
if(A == B)return false;
string tmp = A + B + A + B + A;
return str == tmp;
bool check2(string str,string A,string B){
if(A == B)return false;
int len = str.length();
int al = A.length();
int bl = B.length();
if(len <= 3*(al+bl))return false;
string tmp = string(str.begin(),str.begin()+al+bl);
if(tmp != (A+B))return false;
tmp = string(str.begin()+al+bl,str.begin()+al+bl+al+bl);
if(tmp != (A+B))return false;
tmp = string(str.begin()+al+bl+al+bl,str.end()-al-bl);
if(tmp == A || tmp == B)return false;
tmp = string(str.end()-al-bl,str.end());
if(tmp != (A+B))return false;
return true;
bool check(string str){
int len = str.length();
for(int i = 1;i <= len;i++)
for(int j = 1;j+i <= len;j++)
|| check2(str,string(str.begin(),str.begin()+i),string(str.begin()+i,str.begin()+i+j)) )
return true;
return false;
char ss[100];
int main()
string str;
int T;
int len = strlen(ss);
str = “”;
for(int i = 0;i < len;i++)
if( (ss[i] >= ‘a’ && ss[i] <= ‘z’)
|| (ss[i] >= ‘A’ && ss[i] <= ‘Z’))
str += ss[i];
else printf(“No\n”);
return 0;

------ 本文结束------
  • 本文作者: kuangbin
  • 本文链接: 437.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!