暑期集训2:ACM基础算法 练习题C:CF-1008A
2018学校暑期集训第二天——ACM基础算法
练习题A —— CodeForces - 1008A
Romaji
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.
贪心题
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
char a[110];
int main(void)
{
scanf("%s", a);
int n = strlen(a);
if(a[n-1]=='a' || a[n-1]=='o' || a[n-1]=='u' || a[n-1]=='i' || a[n-1]=='e' || a[n-1]=='n'){
int judge=1;
for(int i=0;i<n-1;i++){
//cout << i <<"=="<<endl;
if(a[i]!='a' && a[i]!='o' && a[i]!='u' && a[i]!='i' && a[i]!='e' && a[i]!='n'){
if(a[i+1]=='a' || a[i+1]=='o' || a[i+1]=='u' || a[i+1]=='i' || a[i+1]=='e'){
}else{
cout << "NO";
judge=0;
break;
}
}
}
if(judge)
cout << "YES";
}else{
cout << "NO";
}
return 0;
}