ZOJ 3818 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 J 题)
2014-09-14 14:46
357 查看
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 are many 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 poem pretty if it can be decomposed into one of the following rhyme scheme: "ABABA" or "ABABCAB". The symbol
A, B and C are different continuous non-empty substrings of the poem. By the way, punctuation characters should be ignored when considering the rhyme scheme.
You are given a line of poem, please determine whether it is pretty or not.
T indicating the number of test cases. For each test case:
There is a line of poem S (1 <= length(S) <= 50). S will only contains alphabet characters or punctuation characters.
题目大意: 给你多个字符串,分别判断每个字符串在去除非字母字符后是否满足可以被分为 ABABA 或者 ABABCAB 形式;
解题思路:纯粹的模拟题,暴力即可;
话虽如此,但还是WA了几遍,我是有多水
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
如有BUG,欢迎指出!!!!
Time Limit: 2 Seconds
Memory Limit: 65536 KB
Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many 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 poem pretty if it can be decomposed into one of the following rhyme scheme: "ABABA" or "ABABCAB". The symbol
A, B and C are different continuous non-empty substrings of the poem. By the way, punctuation characters should 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 integerT indicating the number of test cases. For each test case:
There is a line of poem S (1 <= length(S) <= 50). S will 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
3 niconiconi~ pettan,pettan,tsurupettan wafuwafu
Sample Output
Yes Yes
No
题目大意: 给你多个字符串,分别判断每个字符串在去除非字母字符后是否满足可以被分为 ABABA 或者 ABABCAB 形式;
解题思路:纯粹的模拟题,暴力即可;
话虽如此,但还是WA了几遍,我是有多水
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wronged.gif)
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <vector> #include <ostream> #include <string> #include <cstdlib> #include <cmath> #define PI 3.141592653 using namespace std; typedef long long LL; char str[50+10]; int p; bool check( ) { char stra[55]; char strb[55]; char kstr[55]; char aa[55]; char bb[55]; char cc[55]; for(int i = 1;i < p; i++)// 判定其是否为 ABABA 形式的字符串 { if((p - 3*i)%2==0&&(p-3*i)>0) { int ka=0; int kb=0; int j; for(j = 0;j < i; j++) { stra[ka++] = str[j]; } stra[ka]='\0'; for(;j < i+(p-3*i)/2; j++) { strb[kb++] = str[j]; } strb[kb]='\0'; if(strcmp(stra,strb)==0) continue; sprintf(kstr,"%s%s%s%s%s",stra,strb,stra,strb,stra); if(strcmp(kstr,str)==0) return 1; kstr[0]=='\0'; } } for(int i = 1;i <= p; i++)// 判断其是否为 ABABCAB形式的字符串 { if((p-3*i)>3) { int j,k; for(j = 1;j < p; j++) { int ka,kb,kc; ka=kb=kc=0; if((p-3*i-j)%3==0&&(p-3*i-j)>=3) { for(k = 0; k < i; k++) { aa[ka++]=str[k]; } aa[ka]='\0'; for(k = i;k < i+(p-3*i-j)/3; k++) { bb[kb++]=str[k]; } bb[kb]='\0'; int pk=i*2+2*(p-3*i-j)/3; for(k=pk ;k < pk+j; k++) { cc[kc++]=str[k]; } cc[kc]='\0'; // printf("A->%d B->%d C->%d \n",i,(p-3*i-j)/3,j); if(strcmp(aa,bb)==0||strcmp(aa,cc)==0||strcmp(bb,cc)==0) { continue; } // printf("A->%s B->%s C->%s\n",aa,bb,cc); sprintf(kstr,"%s%s%s%s%s%s%s",aa,bb,aa,bb,cc,aa,bb); if(strcmp(kstr,str)==0) return 1; kstr[0]='\0'; } } } } return 0; } int main( ) { int t; cin>>t; getchar( );//抵消换行符 while(t--) { char c; p = 0; while((c=getchar())!='\n') { if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) { str[p++] = c; } } str[p] = '\0';//这一步很重要 if(check( )) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } } // while(1); return 0; }
如有BUG,欢迎指出!!!!
相关文章推荐
- ZOJ 3809 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 A 题)
- [ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)
- [ACM] zoj 3818 Pretty Poem (2014 ACMICPC Regional 牡丹江站网络赛 J题)
- 2014 ACM-ICPC亚洲区域赛牡丹江站网络预选赛 C Untrusted Patrol
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)
- zoj 3813 Alternating Sum(2014ACMICPC Regional 牡丹江站网络赛 E)
- ZOJ 3820 2014ACM/ICPC牡丹江司B称号
- ZOJ 3822 Domination The 2014 ACM-ICPC 牡丹江区域赛 概率dp 先算概率,再转成期望
- 2014 ACM/ICPC 牡丹江赛区网络赛解题报告汇总
- ZOJ 3818 Pretty Poem The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- 2014牡丹江网络预选赛B题(找规律)zoj3810
- ZOJ3819 ACM-ICPC 2014 亚洲区域赛牡丹江赛区现场赛A题 Average Score 签到题
- 2014牡丹江网络预选赛F题(隐式图BFS暴搜)zoj3814
- 2014牡丹江网络预选赛I题(字符串hash+简单DP)zoj3817
- zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 3820 2014ACM/ICPC牡丹江赛区B题
- zoj 3809 水 2014 ACM牡丹江区域赛网赛
- ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- ZOJ 3811 —— Untrusted Patrol(2014牡丹江网络赛C题)