Header Ads Widget

Easy Pronunciation || codechef solution

 

Problem

Words that contain many consecutive consonants, like "schtschurowskia", are generally considered somewhat hard to pronounce.

We say that a word is hard to pronounce if it contains 4 or more consonants in a row; otherwise it is easy to pronounce. For example, "apple" and "polish" are easy to pronounce, but "schtschurowskia" is hard to pronounce.

You are given a string  consisting of  lowercase Latin characters. Determine whether it is easy to pronounce or not based on the rule above — print YES if it is easy to pronounce and NO otherwise.

For the purposes of this problem, the vowels are the characters {,,,,} and the consonants are the other 21 characters.

Input Format

  • The first line of input will contain a single integer , denoting the number of test cases.
  • Each test case consists of two lines of input.
    • The first line of each test case contains a single integer , the length of string .
    • The second line of each test case contains the string .

Output Format

For each test case, output on a new line the answer — YES if  is easy to pronounce, and NO otherwise.

Each character of the output may be printed in either uppercase or lowercase. For example, the strings YESyeSyes, and YeS will all be treated as identical.

Constraints

  • 1100
  • 1100
  •  contains only lowercase Latin characters, i.e, the characters {,,,,}

Sample 1:

Input
Output
5
5
apple
15
schtschurowskia
6
polish
5
tryst
3
cry
YES
NO
YES
NO
YES

Explanation:

Test case 1: "apple" doesn't have 4 or move consecutive consonants, which makes it easy to pronounce.

Test case 2: "schtschurowskia" has 7 consecutive consonants, which makes it hard to pronounce.

Test case 3: polish doesn't contain 4 or more consecutive consonants, so it's easy to pronounce.

Test case 4: tryst contains 5 consecutive consonants, making it hard to pronounce.

Test case 5: cry doesn't contain any vowels, but its length is less than 4 so it's still easy to pronounce.

Code(c++):-

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
     int n;
     cin>>n;
     string s;
     cin>>s;
     int cons=0;
     for(int i=0;i<n;i++)
     {
     if(s[i]=='a'|| s[i]=='e' || s[i]=='i' || s[i]=='o' ||s[i]=='u')
     {
     cons=0;
     continue;
    
     }
     else
     {
     cons++;
     if(cons>=4)
     break;
     }
    
    
     }
     if(cons>=4)
     cout<<"NO"<<endl;
     else
     cout<<"YES"<<endl;
    
    
    }
    return 0;
}

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-