ZOJ, zoj question category

Source: Internet
Author: User

ZOJ, zoj question category

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 <iostream>#include <cstring>#include <algorithm>#include <cstdio>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;}



Zoj 1151

I spent a long time on AC ......
In fact, tle does not mean that your program has a problem, but it does mean that your program times out during running. That is to say, your program runs slowly, and the result is later than 1 second to determine the timeout.

There are many reasons for timeout. Some are algorithm problems, but your program has no algorithm problems. Therefore, it is only another possibility, that is, the input and output problems.

The c ++ standard input and output cin cout and the string type are all c ++ objects or classes. You must create an object when using it, it is slow to use. It does not affect small-scale acm problems, but when the input is very large, the use of cin cout is much slower than that of scanf and printf.
String is also slower than vector <char>, while vector <char> is slower than char...

For example, I used 0 ms for scanf and printf, and 700 ms for cin and cout (not changed anywhere ......

I used your program template to change it to char [] and changed the input and output to the AC after functions such as gets, printf, and scanf.

I hope that ACM will develop a good habit. Try to use C functions for input and output. Of course, the standard functions of c ++ are not useless, and some functions in stl will soon be used. For example, sort.

Zoj 1151

I spent a long time on AC ......
In fact, tle does not mean that your program has a problem, but it does mean that your program times out during running. That is to say, your program runs slowly, and the result is later than 1 second to determine the timeout.

There are many reasons for timeout. Some are algorithm problems, but your program has no algorithm problems. Therefore, it is only another possibility, that is, the input and output problems.

The c ++ standard input and output cin cout and the string type are all c ++ objects or classes. You must create an object when using it, it is slow to use. It does not affect small-scale acm problems, but when the input is very large, the use of cin cout is much slower than that of scanf and printf.
String is also slower than vector <char>, while vector <char> is slower than char...

For example, I used 0 ms for scanf and printf, and 700 ms for cin and cout (not changed anywhere ......

I used your program template to change it to char [] and changed the input and output to the AC after functions such as gets, printf, and scanf.

I hope that ACM will develop a good habit. Try to use C functions for input and output. Of course, the standard functions of c ++ are not useless, and some functions in stl will soon be used. For example, sort.

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.