ZOJ-3818 Pretty Poem

Source: Internet
Author: User

ZOJ-3818 Pretty Poem

Description

Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. there are too 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 poemPrettyIf it can be decomposed into one of the following rhyme scheme: "ABABA" or "ABABCAB". The symbolA,BAndCAre different continuous non-empty substrings of the poem. By the way, punctuation characters shoshould 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 integerTIndicating the number of test cases. For each test case:

There is a line of poemS(1 <= length (S) <= 50 ).SWill 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 question: to satisfy the string idea of "ABABA" or "ABABCAB" combination: To obtain A and B by violence, launch C
#include 
  
   #include 
   
    #include #include 
    
     using namespace std;int main() {int t;char ch[60];scanf("%d", &t);while (t--) {string str;scanf("%s", ch);int len = strlen(ch);for (int i = 0; i < len; i++)if (isalpha(ch[i]))str += ch[i];len = str.length();int flag = 0;for (int i = 1; i < len/2 && !flag; i++) for (int j = 1; j < len/2 && !flag; j++) {string A = str.substr(0, i);string B = str.substr(i, j);if (A == B)continue;if (A + B + A + B + A == str) {flag = 1;continue;}if (len - (i + j) * 3 > 0) {string AB = A + B;string C = str.substr(2*(i+j), len-3*(i+j));if (A == C || B == C)continue;if (AB + AB + C + AB == str) {flag = 1;continue;}}}if (flag)printf("Yes\n");else printf("No\n");}return 0;}
    
   
  


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.