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.
The first line of the input contains the string ss consisting of |s||s| (1≤|s|≤1001≤|s|≤100) lowercase Latin letters.
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).
sumimasen
YES
ninja
YES
codeforces
NO
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'后面可以接任意字母
输入的字符串如果满足这个条件就输出yes , 反之输出no.
我的蠢代码:
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1;
while(cin >> s1)
{
int flag = 0 , ans=0;
for(int i = 0 ; i < s1.length() ; i++)
{
if(s1[i] == 'n')
{
continue;
}
if(s1[i] != 'a'&&s1[i] != 'e'&&s1[i] != 'i'&&s1[i] != 'o'&&s1[i] != 'u')
{
if(s1[i+1] != 'a'&&s1[i+1] != 'e'&&s1[i+1] != 'i'&&s1[i+1] != 'o'&&s1[i+1] != 'u')
{
flag = 1;
}
}
}
if(s1[s1.length()-1] != 'a'&&s1[s1.length()-1] != 'e'&&s1[s1.length()-1] != 'i'&&s1[s1.length()-1] != 'o'&&s1[s1.length()-1] != 'u'&&s1[s1.length()-1] != 'n')
{
flag = 1;
}
if(flag == 1 )
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}
用map的代码: #include <stdio.h>
#include <iostream>
#include <map>
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<char , int> M;
string s1;
int flag = 0;
M['a'] = 1;M['e'] = 1;M['i'] = 1;M['o'] = 1;M['u'] = 1;
cin >> s1;
for(int i = 0 ; i < s1.length() ; i++)
{
if(s1[i] == 'n')
{
continue;
}
else
{
if(M[s1[i]] != 1 && M[s1[i+1]] != 1)
{
flag = 1;
break;
}
}
}
if(flag== 1)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
return 0;
}
一定要学好STL!!!!