Good or Bad LightOJ - 1051

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

详解:http://www.cnblogs.com/jianglangcaijin/archive/2012/10/12/2721156.html

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 int n;
 8 int a[60],d1[60][6],d2[60][6];
 9 char S[60];
10 
11 int OK(char x){
12     return x=='A'||x=='E'||x=='I'||x=='O'||x=='U';
13 }
14 
15 void Inite(){
16     memset(d1,0,sizeof(d1));
17     memset(d2,0,sizeof(d2));
18     d1[0][0]=d2[0][0]=1;
19     for(int i=1;i<=n;i++){
20         if(S[i]=='?') a[i]=2;
21         else if(OK(S[i])) a[i]=0;
22         else a[i]=1;
23     }
24 }
25 
26 void solve(){
27     for(int i=1;i<=n;i++){
28         for(int j=0;j<=2;j++) if(d1[i-1][j])
29         {    
30             if(a[i]==2||a[i]==1) d2[i][1]=1;
31             if(a[i]==2||a[i]==0) d1[i][j+1]=1;
32         }
33         for(int j=0;j<=4;j++) if(d2[i-1][j])
34         {
35             if(a[i]==2||a[i]==0) d1[i][1]=1;
36             if(a[i]==2||a[i]==1) d2[i][j+1]=1;
37         }
38     }
39     
40     int bad=0,good=0;
41     for(int i=0;i<=2;i++) if(d1[n][i]) good=1;
42     for(int i=0;i<=4;i++) if(d2[n][i]) good=1;
43     for(int i=1;i<=n;i++) if(d1[i][3]||d2[i][5]) bad=1;
44     if(good&&bad) puts("MIXED");
45     else if(good) puts("GOOD");
46     else puts("BAD");
47 }
48 
49 int main()
50 {   int kase;
51     cin>>kase;
52     for(int t=1;t<=kase;t++){
53         scanf("%s",S+1);
54         n=strlen(S+1);
55         printf("Case %d: ",t);
56         Inite();
57         solve();
58     }
59     return 0;
60 } 

 

转载于:https://www.cnblogs.com/zgglj-com/p/7512794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值