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



0 0
原创粉丝点击