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;}