您的位置:首页 > 编程语言 > Go语言

LightOJ 1051 Good or Bad

2016-08-06 13:19 375 查看
题意:给你一个字符串,只包含大写字母和‘?’,如果字符串中出现了连续三个以上的元音字母或者连续五个以上的辅音字母,则这个字符串是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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM lightoj 动态规划