a tv ptoui bontres zoggax wiinq eep houctuh end
<a> is acceptable. <tv> is not acceptable. <ptoui> is not acceptable. <bontres> is not acceptable. <zoggax> is not acceptable. <wiinq> is not acceptable. <eep> is acceptable. <houctuh> is acceptable.
题意很好理解,仔细思考一下想到了应该将条件划分,就像数字电路 对应三个条件的输入状态 映射输出状态 下面代码中 只有0 1 0 的条件下 才输出1(acceptable);
接下来 问题转化为如何设计去 对三个条件加以判断的问题
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
char cnt[100];//cnt数组用0和1两种状态标志str中原音和辅音情况
void ls(string &str)
{
for(int m=0;m<str.size();m++)
if(str[m]=='a'||str[m]=='e'||str[m]=='i'||str[m]=='o'||str[m]=='u')
cnt[m]=1;
}
int main()
{
string str;
int flag1,flag2,flag3;
while(cin>>str,str!="end")
{
flag1=flag2=flag3=0;
memset(cnt,0,sizeof(cnt));ls(str);
if((str.size()==1))//接下来根据flag1 2 3 的状态分别判断三个条件的情况
flag1=cnt[0]==1?0:1;
else
{
for(int i=0;i<(str.size()-2);i++)
//str。size()-2的值不是-1 是正数在str只有一个字母的时候 要单独判断一个元素的情况
{
if((cnt[i]==cnt[i+1])&&(cnt[i+1]==cnt[i+2]))
{
flag1=1;
break;
}
}
}
for(int j=0;j<str.size();j++)
if(cnt[j]==1)
flag2=1;
for(int k=0;k<str.size()-1;k++)
if(str[k]==str[k+1])
if((str[k]=='e')||(str[k]=='o'))
continue;
else
{
flag3=1;
break;
}
if(((flag1==0)&&(flag3==0))&&(flag2==1))//如果flag三个条件同时满足则……
cout<<"<"<<str<<">"<<" is acceptable."<<endl;
else
cout<<"<"<<str<<">"<<" is not acceptable."<<endl;
}
return 0;
}
杭电 HDU 1039 Easier Done Than Said?
原文:http://blog.csdn.net/lsgqjh/article/details/44514885