ZOJ 3813 Pretty Poem (violence)

Source: Internet
Author: User

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 is many famous poets in the contemporary era. It is said a few ACM-ICPC contestants can even write poetic code. Some poems have a strict rhyme scheme like "Ababa" or "Ababcab". For example, "Niconiconi" was composed of a rhyme scheme "ababa" with a = "ni" and B = "CO".

More technically, we call a poem pretty if it can being decomposed into one of the following rhyme scheme: "Ababa" O R "Ababcab". The symbolA, B and C are different continuous non-empty substrings of the poem. By the punctuation characters should is ignored when considering the rhyme scheme.

You were given a line of poem, please determine whether it was pretty or not.

Input

There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:

There is a line of poem S (1 <= Length ( S ) <=). Would only contains alphabet characters S or punctuation Characters.

Output

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

Sample Input
3niconiconi~pettan,pettan,tsurupettanwafuwafu
Sample Output
Yesyesno


Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3818

Problem-solving ideas: string processing, direct violence enumeration A,b,c, directly determine whether to meet the two situations. Note A,b,c are different, I am two cases of classification open processing, the second case of AB as a substring directly judged, but also to judge AB can be decomposed into two different substrings, a, B and not the same as C.

The code is as follows:

#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <string > #include <algorithm> #include <string>using namespace Std;//const int maxn=205;int main (void) {int t; scanf ("%d", &t), while (t--) {string s,a;cin>>s;int p=0,n=0;int len=s.length (); for (int i=0;i<len;i++) if (s [i]>= ' A ' &&s[i]<= ' Z ' | | S[i]>= ' a ' &&s[i]<= ' Z ') {a+=s[i];n++;}   for (int l1=1;l1<=n;l1++)//first case Ababa judgment {string a=a.substr (0,L1); Substring a always starts at the first position for the for (int l2=1;l2<=n;l2++) {if (l1+l2+l1+l2+l1>n)//length and is greater than the main string, without having to enumerate backwards break;string b=a.substr (L1,  L2); Substring B is always next to string AIF (A==A+B+A+B+A&AMP;&AMP;A!=B) {p=1;break;}} if (p) break;} if (p) {printf ("yes\n"); continue;}   for (int l1=2;l1<=n;l1++)//second case Ababcab judgment {string ab=a.substr (0,L1); Consider AB as a substring for (int l2=1;l2<=n;l2++) {if (l1+l1+l2+l1>n) break;string c=a.substr (2*L1,L2); if (A==AB+AB+C+AB)// Further judging when conditions are met the AB can be decomposed into different substrings A and b{int lab=ab.length (); for (int k=1;k<lab;k++) {string a=ab.subSTR (0,k); string B=ab.substr (K,lab-k); if (a!=c&&a!=b&&b!=c) {p=1;break;}} if (p) break;}} if (p) break;} if (p) printf ("yes\n"); elseprintf ("no\n");}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ZOJ 3813 Pretty Poem (violence)

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.