题意:对一个字符串s进行处理,有三个条件:第一,该字符串至少含有一个元音;第二,字符串不能含有连续的三个元音或者辅音;第三,字符串不能含相邻的两个字符相等,除了“ee”和“oo”外,如果字符串s满足三个条件,输出"<s> is acceptable."否则输出”<s> is not acceptable.“。
解题思路:该题关键点是判断三个条件:是否含有一个元音,是否含有连续的三个元音或者辅音,是否含有相邻的两个字符相等,可以分别写三个判断函数进行依次判断,详见code。
code:
#include <iostream>
#include <string>
using namespace std;
string vowel;
int isvowel(char s)
{
if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') return 1;
else return 0;
}
int judge1(int n)
{
for(int i = 2; i < n; i++)
{
if(isvowel(vowel[i-2]) && isvowel(vowel[i-1]) && isvowel(vowel[i])) return 0;
if(!isvowel(vowel[i-2]) && !isvowel(vowel[i-1]) && !isvowel(vowel[i])) return 0;
}
return 1;
}
int judge2(int n)
{
for(int i = 0; i < n; i++)
{
if(isvowel(vowel[i])) return 1;
}
return 0;
}
int judge3(int n)
{
for(int i = 1; i < n; i++)
{
if(vowel[i-1] == vowel[i] && vowel[i] != 'e'&& vowel[i] != 'o') return 0;
}
return 1;
}
int main()
{
while(cin>>vowel && vowel != "end")
{
int len = vowel.length();
if(judge1(len) == 0)
{
cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
continue;
}
if(judge2(len) == 0)
{
cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
continue;
}
if(judge3(len) == 0)
{
cout<<"<"<<vowel<<">"<<" is not acceptable."<<endl;
continue;
}
cout<<"<"<<vowel<<">"<<" is acceptable."<<endl;
}
return 0;
}