Description:
Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are “a”, “o”, “u”, “i”, and “e”. Other letters are consonant.
In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant “n”; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words “harakiri”, “yupie”, “man”, and “nbo” are Berlanese while the words “horse”, “king”, “my”, and “nz” are not.
Help Vitya find out if a word ss is Berlanese.
Input
The first line of the input contains the string ss consisting of |s||s| (1≤|s|≤1001≤|s|≤100) lowercase Latin letters.
Output
Print “YES” (without quotes) if there is a vowel after every consonant except “n”, otherwise print “NO”.
You can print each letter in any case (upper or lower).
Examples
Input
sumimasen
Output
YES
Input
ninja
Output
YES
Input
codeforces
Output
NO
Note
In the first and second samples, a vowel goes after each consonant except “n”, so the word is Berlanese.
In the third sample, the consonant “c” goes after the consonant “r”, and the consonant “s” stands on the end, so the word is not Berlanese.
这道题就是判断每个除了n之外的辅音后面是否是元音即可,但是一定要注意!!敲黑板!!除了n之外的辅音后面是n应该是输出NO的,因为这个检查了好久才发现。
#include<iostream>
#include<string>
using namespace std;
char v[5]={'a','e','i','o','u'};
bool Isvol(char c){
for(int i=0;i<5;i++)
if(v[i]==c)
return true;
return false;
}
int main(){
string s;
cin>>s;
int len=s.size();
if( (!Isvol(s[len-1]) ) && (s[len-1]!='n') ){//结尾只能是元音或者n
cout<<"NO"<<endl;
return 0;
}
for(int i=0;i<len-1;i++){
if( (!Isvol(s[i])) && (s[i]!='n') ){//碰到除n之外的辅音检查其后单词
if(!Isvol(s[i+1])){
cout<<"NO"<<endl;
return 0;
}
}
}
cout<<"YES"<<endl;
return 0;
}
我在最前面首先判断单词最后一个单词,若是除n之外的辅音则直接输出NO。