Given the length of a word (wordLen) and the maximum number of consecutive vowels that it can contain (maxVowels), determine how many unique words can be generated. Words will consist of English alphabetic letters a through z only. Vowels are v: {a, e, i, o, u}; consonants are c: remaining 21 letters. In the explanations, v and c represent vowels and consonants.

Respuesta :

Answer:

Check the explanation

Step-by-step explanation:

C+++ CODE:

#include<bits/stdc++.h>

using namespace std;

//implementing function calculateWays

int calculateWays(int wordlen , int maxvowels)

{

//if max vowels = 0 calculating ways

if(maxvowels==0)

{

int ways = 1;

//loop for calculating ways

for(int i=0 ; i<wordlen ; i++)

{

ways = ways*21;

}

return ways;

}

else

{

if(wordlen==1)//if word length is 1

{

int c = 1, v = 1;

int ways = c*21 + v*5; //calculating ways

return ways;

}

else // if max vowels and world length both are greater then 1

{

int ways = 0;

//loop to calculating

for(int i=0 ; i<wordlen ; i++)

{

int c = 1, v = 1;

for(int j=0 ; j<wordlen-maxvowels ; j++)

{

c = c*21;

}

for(int k=0 ; k<maxvowels ; k++)

{

v = v*5;

}

ways = ways + (v*c); // calculating ways with vowels

}

int ways1 = 1;

for(int i=0 ; i<wordlen ; i++)

{

ways1 = ways1*21; //calculating ways without vowels

}

return ways + ways1 ; //return total ways

}

}

}

int main()

{

int wordlen , maxvowels;// declaring variables

cin>>wordlen>>maxvowels; // reading inputs from user

int ways = calculateWays(wordlen , maxvowels); //passing values to function calculateWays

cout<<ways; //printing ways

return 0;

}

Kindly check the attached images below to see the Code Screenshot and Code Output.

Ver imagen temmydbrain
Ver imagen temmydbrain
Ver imagen temmydbrain