Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Chef has a string S with him. Chef is happy if the string contains a contiguous substring of length strictly greater than 2 in which all its characters are vowels.
Determine whether Chef is happy or not.
Note that, in english alphabet, vowels are a
, e
, i
, o
, and u
.
For each test case, if Chef is happy, print HAPPY
else print SAD
.
You may print each character of the string in uppercase or lowercase (for example, the strings hAppY
, Happy
, haPpY
, and HAPPY
will all be treated as identical).
Input:
4
aeiou
abxy
aebcdefghij
abcdeeafg
Output:
Happy
Sad
Sad
Happy
Test case 1: Since the string aeiou
is a contiguous substring and consists of all vowels and has a length >2, Chef is happy.
Test case 2: Since none of the contiguous substrings of the string consist of all vowels and have a length >2, Chef is sad.
Test case 3: Since none of the contiguous substrings of the string consist of all vowels and have a length >2, Chef is sad.
Test case 4: Since the string eea
is a contiguous substring and consists of all vowels and has a length >2, Chef is happy.
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int t;
Scanner scan=new Scanner(System.in);
t=scan.nextInt();
while(t-->0){
String str;
int count=0;
str=scan.next();
int j=str.length();
for(int i=0;i<j;i++){
if(str.charAt(i)=='a'||str.charAt(i)=='e'||str.charAt(i)=='i'||str.charAt(i)=='o'||str.charAt(i)=='u'){
count++;
}
else{
count=0;
}
if(count==3){
System.out.println("Happy");
break;
}
}
if(count!=3){
System.out.println("Sad");
}
}
}
}
#include <iostream>
#include<string>
using namespace std;
int isVowel(char ch){
return ch=='a'|| ch=='e' || ch=='i' || ch=='o' || ch=='u';
}
int main() {
int t;
cin>>t;
while(t--)
{
string s;
int flag=0;
cin>>s;
for(int i=0;i<s.length()-2;i++){
if(isVowel(s[i])&&isVowel(s[i+1])&&isVowel(s[i+2])){
flag=1;
break;}
}
if(flag){
cout<<"Happy"<<endl;
}
else{
cout<<"Sad"<<endl;
}
}
return 0;
}
n = int(input())
while(n):
list1 = ['a', 'e', 'i', 'o', 'u']
n = n-1
count = 0
str1 = input()
for i in str1:
if i in list1:
count = count+1
if count > 2:
break
else:
count = 0
if count > 2:
print("Happy")
else:
print('Sad')
In our experience, we suggest you solve this Chef and Happy String CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Chef and Happy String CodeChef Solution
I hope this Chef and Happy String CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>