Given a string SS your task is to find out whether a string is Noble Vowel string or not. A Nobel Vowel string is one in which there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant nn; after this letter, there can be any letter (not only a vowel) or there can be no letter at all.
Input format
The first line contains an integer T denoting the number of test cases. Each test case consists of one string S consisting of lower case alphabets.
Output format
For each test case on a new line print YES if S is a Noble Vowel string else print NO .
Constraints:
1<=T<=10
1<=|S|<=1000
Time Limit
1 second
Example
Input
2
aeiou
cefduo
Output
YES
NO
Explanation
In the first string, every vowel is followed by another vowel or consonant. So the string is Noble Vowel. In the second string, ff is a consonant, which should be followed by a vowel but it is being followed by another consonant, so this string is not Noble Vowel.
Start from index 0 and check the current character. If the current character is not vowel(i.e. consonant) then immediately check the next character. If the next character is also a consonant then the string is not Nobel Vowel.
Here the code :- #include <bits/stdc++.h>
using namespace std;
Given a string SS your task is to find out whether a string is Noble Vowel string or not. A Nobel Vowel string is one in which there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant nn; after this letter, there can be any letter (not only a vowel) or there can be no letter at all.
Input format
The first line contains an integer TT denoting the number of test cases. Each test case consists of one string SS consisting of lower case alphabets.
Output format
For each test case on a new line print YES if SS is a Noble Vowel string else print NO .
Constraints:
1<=T<=101<=T<=10 1<=|S|<=10001<=|S|<=1000
Time Limit
11 βsecon
Example
Input
2 aeiou cefduo
Output
YES NO
Explanation
In the first string, every vowel is followed by another vowel or consonant. So the string is Noble Vowel. In the second string, ff is a consonant, which should be followed by a vowel but it is being followed by another consonant, so this string is not Noble Vowel.
import java.util.;
import java.io.;
public class Main {
public static void main(String args[]) throws IOException {
//write your code here
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T!=0){
int flag=0;
int i;
String s=sc.next();
String str=s.toLowerCase();
char c[]=str.toCharArray();
for(i=0;i<str.length()-1;i++)
{
if(c[i]!=βaβ&&c[i]!=βeβ&&c[i]!=βiβ&&c[i]!=βoβ&&c[i]!=βuβ&&c[i]!=βnβ){
if(c[i+1]!=βaβ&&c[i+1]!=βeβ&&c[i+1]!=βiβ&&c[i+1]!=βoβ&&c[i+1]!=βuβ){
flag=1;
break;
}
}
if(c[i]!=βaβ&&c[i]!=βeβ&&c[i]!=βiβ&&c[i]!=βoβ&&c[i]!=βuβ&&c[i]!=βnβ){ In these line why you write c[i]!=βnβ.Here n is not a vowel
it cannot correct for all test cases but my code is run for test case // program to check the noble vowel string
// program to check the noble vowel string #include #include
using namespace std;
int isvowel(char ch);//check the chrater is vowel or not
//driver function
int main()
{
int check=0,t;
cin>>t;
while(t--){
check=0;
string data;
cin>>data;
int i=0;
while(i!=data.length())// to check the complete string
{
if(check==0)//contion when next can be anything
{
if(isalpha(data[i]))
{
if(isvowel(data[i]))
check=0;
else
{
if(data[i]=='n')
check=0;
else
check=1;
}
}
else
check=-1;
}
else if(check==1)
{
if(isvowel(data[i]))
check=0;
else
check=-1;
}
else if(check==-1)//-1 indicate the string break the rules
break;
i++;
}
if(check==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
Hi @deepakstark47, I have a doubt, why there is a condition that the last character has to be a vowel and n? what is the problem if the last character is a consonant?
I am talking abt this :
if(i==str.length()-1 && (c[i]==βaβ||c[i]==βeβ||c[i]==βiβ||c[i]==βoβ||c[i]==βuβ||c[i]==βnβ))
flag=0;
else{
flag=1;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(tβ>0)
{
String b=br.readLine();
String s=b.toLowerCase();
boolean flag=false;
int len=s.length();
in JAVA it worked. The extra condition is we have to check for the last character as vowel or βnβ.
import java.util.;
import java.io.;
public class Main {
public static void main(String args[]) throws IOException {
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
while(T!=0){
int flag=0;
int i;
String s=sc.next();
String str=s.toLowerCase();
char c[]=str.toCharArray();
for(i=0;i<str.length()-1;i++)
{
if(c[i]!=βaβ&&c[i]!=βeβ&&c[i]!=βiβ&&c[i]!=βoβ&&c[i]!=βuβ&&c[i]!=βnβ){
if(c[i+1]!=βaβ&&c[i+1]!=βeβ&&c[i+1]!=βiβ&&c[i+1]!=βoβ&&c[i+1]!=βuβ){
flag=1;
break;
}
}
}
if(i==str.length()-1 && (c[i]==βaβ||c[i]==βeβ||c[i]==βiβ||c[i]==βoβ||c[i]==βuβ||c[i]==βnβ))
flag=0;
else{
flag=1;
}