#include<iostream>
#include<string>
using namespace std;
string str;
int pos;
bool isYuan(char c) //判断是否为元音
{
return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
bool yuan() //遍历元音段
{
int len=0;
for(;pos<=str.length();pos++){
if(!isYuan(str[pos])) break;
len++;
}
return len;
}
bool zhuo() //遍历辅音段
{
int len=0;
for(;pos<=str.length();pos++){
if(isYuan(str[pos])) break;
len++;
}
return len;
}
bool serch() //开始遍历
{
pos=0;
if(zhuo()&&yuan()&&zhuo()&&yuan()&&pos==str.length()) return true;
else return false;
}
int main()
{
cin>>str;
if(serch()) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
}
这段代码如果按照题意来说应该不正确吧?‘lol'只有三段也能输出yes,正确的应该是怎样写的?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2020-10-16 23:52关注
c++的话,用正则表达式即可
^([^aeiou]+[aeiou]+){2}$
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 maple软件,用solve求反函数出现rootof,怎么办?
- ¥50 汇编语言除法溢出问题
- ¥65 C++实现删除N个数据列表共有的元素
- ¥15 Visual Studio问题
- ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
- ¥20 求一个html代码,有偿
- ¥100 关于使用MATLAB中copularnd函数的问题
- ¥20 在虚拟机的pycharm上
- ¥15 jupyterthemes 设置完毕后没有效果
- ¥15 matlab图像高斯低通滤波