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
Answers
Answer:
Vowels are defined as sound repeated as a, e, i, o, u and the rest 21 letters are classified as consonants.
Step-by-step explanation:
1) Speed is fast = SPEEFAS
2) Minimum number of participants = MINIPART
3) Sum of excess = SUMCESS
These words are generated from English alphabet as a combination of Vowels and alphabets. thus the combination of vowels and consonant help in the formation of words. There are n number of unique letters are formed.
The length of the word "wordlen" = 2
The length of the word "maxVowels" = 1
Words take the form. There is a vowel in the first position, the second position or no position.
The total distinct words possible is and 651 modulo 1000000007= 651.
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;
}
The length of the word "wordlen" = 2
The length of the word "maxVowels" = 1
Words take the form. There is a vowel in the first position, the second position or no position.
The total distinct words possible is and 651 modulo 1000000007= 651.
#SPJ2