Algorithm


 problem Link :  https://www.codechef.com/problems/HAPPYSTR 

Problem

Chef has a string  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 aeio, and u.

Input Format

  • First line will contain , number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, a string .

Output Format

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 hAppYHappyhaPpY, and HAPPY will all be treated as identical).

Constraints

  • 1≤�≤1000
  • 3≤∣�∣≤1000, where ∣�∣ is the length of .
  •  will only contain lowercase English letters.

Sample 1:

Input
 
Output
 
4
aeiou
abxy
aebcdefghij
abcdeeafg
Happy
Sad
Sad
Happy

Explanation:

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. 

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include<stdio.h>
#include < string.h>

int vcheck(char ch)
{
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return 1;
    else return 0;
}

int main()
{
    int t,l,i;
    char str[1000];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",str);
        l=strlen(str);
        int count=0;
        for(i=0;i<l;i++)
        {
            if(vcheck(str[i])==1 && vcheck(str[i+1])==1 && vcheck(str[i+2])==1) count++;
        }
        if(count==0) printf("Sad\n");
        else printf("Happy\n">;
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
4
aeiou
abxy
aebcdefghij
abcdeeafg

Output

x
+
cmd
Happy
Sad
Sad
Happy
Advertisements

Demonstration


CodeChef solution HAPPYSTR  - Chef and Happy String Codechef solution in C,C++

Previous
#70 Leetcode Climbing Stairs Solution in C, C++, Java, JavaScript, Python, C# Leetcode
Next
#72 Leetcode Edit Distance Solution in C, C++, Java, JavaScript, Python, C# Leetcode