ZOJ 3818 Pretty Poem (brute force simulation string (SUBSTR))

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
Author: JIANG, Kai
Source: The acm-icpc Asia Mudanjiang Regional first Round


Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5350


Question: Ask whether the remaining string after removing non-alphabetic characters satisfies the structure of Ababa or Ababcab, where ABC is a different substring


Title Analysis: First get the target string, and then enumerate the substrings A and B, which is used in the STL string substr function (sub = S.SUBSTR (startpos, Len)), enumeration when enumerated to the LEN/2, because AB obviously may be more than len/ 2, the rest is pure simulation, the key is substr Dafa good ~


#include <cstdio> #include <cstring> #include <string>using namespace Std;char get[55];int main () {int    T    scanf ("%d", &t);         while (t--) {scanf ("%s", get);        string S;        BOOL flag = FALSE;        int len = strlen (get); for (int i = 0; i < len; i++) if ((Get[i] >= ' A ' && get[i] <= ' Z ') | |                (Get[i] >= ' A ' && get[i] <= ' z '))        s + = Get[i];        Len = S.length ();                for (int i = 1, i < LEN/2; i++) {for (int j = 1; j < Len/2; J + +) {                 String A = S.substr (0, I);                 String B = S.substr (i, j);                if (A = = B) continue;                    if (A + B + A + b + a = = s) {flag = true;                Break                     } if ((i + j) * 3 < Len) {string AB = A + B; String C = S.substr ((i + j) * 2, Len-(i + j) * 3); if (A = = C | |                    B = = C) continue;                         if (ab + ab + C + ab = = s) {flag = true;                     Break        }}} if (flag) break; } printf ("%s\n", flag?)    "Yes": "No"); }}




ZOJ 3818 Pretty Poem (brute force simulation string (SUBSTR))

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.