Given a sentence as a string S. Write a program to calculate difficulty of a given sentence. A word in the given string is considered hard if it has 4 consecutive consonants or number of consonants are more than number of vowels. Else the word is easy. Difficulty of sentence is defined as 5*(number of hard words) + 3*(number of easy words).
Note: uppercase and lowercase characters are same.
Input:
First line of input contains a single integer T which denotes the number of test cases. Then T test cases follows. First line of each test case contains a string S which denotes the sentence.
Output:
For each test case print the difficulty of the sentence as described above.
Constraints:
1<=T<=100
1<= length( S ) <= 105
Example:
Input:
1
Difficulty of sentence
Output:
13
Your Code
#include<iostream>
using namespace std;
int isvowel(char c)
{
if(c=='a'||c=='i'||c=='o'||c=='e'||c=='u')
{
return 1;
}
else
return 0;
}
int main()
{
int t;
cin>>t;
cin.ignore();
while(t--)
{
string s;
getline(cin,s);
// cout<<s;
int l;
l=s.length();
int i;
int count=0,num=0,easy=0,hard=0;
for(i=0; i<l; i++)
{
if(s[i]!=' ' )
{
if(isvowel(s[i])==1)
{
num++;
}
else
{
count++;
}
//cout<<count<<" "<<num<<endl;
}
if(s[i]==' '|| i==l-1)
{
if(count>num)
{
hard++;
}
else
{
easy++;
}
count=0; num=0;
}
}
for(i=0; i<l-3; i++)
{
if(s[i]!=' ')
{
if(isvowel(s[i])==0 && isvowel(s[i+1])==0 && (s[i+2])==0 && (s[i+3])==0)
{
hard++;
}
}
}
int ans=5*hard+3*easy;
cout<<ans<<endl;
//cout<<easy<<hard;
}
}