LightOJ 1051 Good or Bad

题意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上的元音字母或者连续五个以上的辅音字母,则这个字符串是bad,不然就是good.

‘?’号可以替换任意字母,即可bad有可good,则输出Mixed.


分析:dpy[i][j]表示到i为止,连续j个元音可否达到。dpf表示辅音。

            这个转移当达到3个元音或者5个辅音时后面就不在转移了,即全是零。  所以找是否是mixed只需扫最后一个位置的前两个元音或者前4个辅音是否不为0。

            不懂可以打印下屏蔽的代码,研究下。



#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<cctype>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>
#include<limits>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N= 2000;
const int maxn = 1e2+10;
const int maxm = 2000000001;
const int MOD = 1000;
int dpy[maxn][maxn],dpf[maxn][maxn];   //元音  辅音  到i为止,连续j个元音可否达到
char str[maxn];
int main(){
#ifdef LOCAL
	freopen("C:\\Users\\lanjiaming\\Desktop\\acm\\in.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
    int T,kase = 0;
    cin>>T;
    while(T--)
    {
        cout<<"Case "<<++kase<<": ";
        cin>>str;
        int len = strlen(str);
        memset(dpy,0,sizeof(dpy));
        memset(dpf,0,sizeof(dpf));
        for(int i = 0; i < len; i++)
        {
            int x;
            if (str[i] == '?') x = 0;
            else if (str[i] == 'A' || str[i]=='E' || str[i]=='I' || str[i]=='O'||str[i]=='U')
                  x = 1;
                 else x = 2;
            if (i==0)
            {
                if ( x == 1 || x == 0) dpy[0][1] = 1;
                if ( x == 2 || x == 0) dpf[0][1] = 1;
            }else
             {
                 for(int j = 0; j <= 2; j++)
                    if (dpy[i-1][j])
                    {
                         if ( x == 1 || x == 0) dpy[i][j+1] = 1;
                         if ( x == 2 || x == 0) dpf[i][1] = 1;
                    }
                 for(int j = 0; j <= 4; j++)
                    if (dpf[i-1][j])
                    {
                         if ( x == 1 || x == 0) dpy[i][1] = 1;
                         if ( x == 2 || x == 0) dpf[i][j+1] = 1;
                    }
             }
        }
       /* for(int i = 0; i < len; i++)
        {
            cout<<i<<endl;
            for(int j = 0; j <= 3; j++) cout<<dpy[i][j]<<" ";cout<<endl;
            for(int j = 0; j <= 5; j++) cout<<dpf[i][j]<<" ";cout<<endl;
        }*/

        bool ok1 =false,ok2 = false;
        for(int i = 0; i < len; i++)
           if (dpy[i][3] || dpf[i][5]) ok2 =true;
           
        for(int i = 0; i <= 2; i++)
             if (dpy[len-1][i]) ok1 =true;
        for(int i = 0; i <= 4; i++)
             if (dpf[len-1][i]) ok1 =true;
             
        if (ok1 && ok2 ) cout<<"MIXED\n";
        else if (ok1) cout<<"GOOD\n";
              else cout<<"BAD\n";
    }
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值