LightOJ 1051 Good or Bad
来源:互联网 发布:精灵恢复软件 注册码 编辑:程序博客网 时间:2024/06/05 19:27
A string is called bad if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called good if it is not bad. You are given a string s, consisting of uppercase letters('A'-'Z') and question marks('?'). Return "BAD" if the string is definitely bad (that means you cannot substitute letters for question marks so that the string becomes good), "GOOD" if the string is definitely good, and "MIXED" if it can be either bad or good.
The letters 'A', 'E', 'I', 'O', 'U' are vowels, and all others are consonants.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case begins with a non-empty string with length no more than 50.
Output
For each case of input you have to print the case number and the result according to the description.
Sample Input
5
FFFF?EE
HELLOWORLD
ABCDEFGHIJKLMNOPQRSTUVWXYZ
HELLO?ORLD
AAA
Sample Output
Case 1: BAD
Case 2: GOOD
Case 3: BAD
Case 4: MIXED
Case 5: BAD
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,a[55],f1[55][4],f2[55][6];char s[55];int change(char c){ if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U') return 1; else return 0;}void dp(){ memset(f1,0,sizeof(f1)); memset(f2,0,sizeof(f2)); f1[0][0]=f2[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=2;j++) if(f1[i-1][j]) { if(a[i]==2||a[i]==1) f2[i][1]=1; if(a[i]==2||a[i]==0) f1[i][j+1]=1; } for(int j=0;j<=4;j++) if(f2[i-1][j]) { if(a[i]==2||a[i]==0) f1[i][1]=1; if(a[i]==2||a[i]==1) f2[i][j+1]=1; } } int bad=0,good=0; for(int i=0;i<=2;i++) if(f1[n][i]) good=1; for(int i=0;i<=4;i++) if(f2[n][i]) good=1; for(int i=1;i<=n;i++) if(f1[i][3]||f2[i][5]) bad=1; if(good&&bad) printf("MIXED\n"); else if(good) printf("GOOD\n"); else printf("BAD\n");}int main(){ int T; scanf("%d",&T); for(int qq=1;qq<=T;qq++) { scanf("%s",s+1); n=strlen(s+1); for(int i=1;i<=n;i++) { if(s[i]=='?') a[i]=2; else if(change(s[i])) a[i]=0; else a[i]=1; } printf("Case %d: ",qq); dp(); } return 0;}
- LightOJ 1051 Good or Bad
- LightOJ 1051 Good or Bad
- LightOJ 1051 Good or Bad 解题报告
- LightOJ - 1051 Good or Bad(扫描)
- LightOJ 1051 - Good or Bad(dp)
- LightOJ 1051 - Good or Bad (dp)
- LightOJ 1051 - Good or Bad(DP)
- lightoj 1051 - Good or Bad DP
- LightOJ 1051 Good or Bad (递推DP)
- good man or bad man?
- STORED PROCEDURES: GOOD OR BAD(存储过程:好还是坏)
- Are You a Good Leader or a Bad Leader
- good and bad
- Good Bad Books
- good day !bad day !
- Good vs Bad Leader
- Good and Bad PHP Code
- c++ good() eof() fail() bad()
- linux查看文件系统类型
- Android UI学习之Dialog
- POJ 2251:Dungeon Master【bfs】
- Android getVisibility()返回值对应的状态
- JSP基础语法篇——编程题
- LightOJ 1051 Good or Bad
- caffe study(4) - 优化算法基本原理
- ExtJs5.1多选下拉框CheckComb
- 机械硬盘HDD
- 基于V4L2驱动程序的USB摄像头Android(JNI)的编写(一)
- 《父与子的编程之旅》——可计数与不可计数的循环
- MySQL文件结构
- CUDA安装
- Android Http请求框架一:Get 和 Post 请求