Vowels and consonant

Practice

Author: Anurag
Tester: Anurag
Editorialist: Anurag

DIFFICULTY:

EASY,MEDIUM,GREEDY,STRING,CAKEWALK, SIMPLE

PREREQUISITES:

Math ,String

PROBLEM:

Chef has given a task he has given a string and he has to count a number of consonant and number of vowels in the given string you have to help chef to do his task at a time .

EXPLANATION:

Chef has given a task he has given string his task is to count number of consonant and number of vowels in the string so we have to just iterate the loop if there is and vowels then we will store it in the count of vowels other wise count in consonant and later we will print the count of consonant and vowels

for example :

anurag
here count of vowel is 3 that is a 2 time and u 1 time and other 3 are consonant
hence the output is 3 3

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
cin>>ws;
string s;
cin>>s;
ll conscnt=0;
ll vowcnt=0;
//int i=0;
for(int i=0;i<s.length();i++){
if(s[i]== ‘a’ || s[i]==‘A’|| s[i]==‘e’ || s[i]==‘E’ || s[i]==‘i’ || s[i]==‘I’ || s[i]==‘o’ || s[i]==‘O’ || s[i]==‘u’ || s[i]==‘U’)
vowcnt++;

else conscnt++;
}  
cout<<vowcnt<<" "<<conscnt;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
cin>>ws;
string s;
cin>>s;
ll conscnt=0;
ll vowcnt=0;
//int i=0;
for(int i=0;i<s.length();i++){
if(s[i]== ‘a’ || s[i]==‘A’|| s[i]==‘e’ || s[i]==‘E’ || s[i]==‘i’ || s[i]==‘I’ || s[i]==‘o’ || s[i]==‘O’ || s[i]==‘u’ || s[i]==‘U’)
vowcnt++;

else conscnt++;
}  
cout<<vowcnt<<" "<<conscnt;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
cin>>ws;
string s;
cin>>s;
ll conscnt=0;
ll vowcnt=0;
//int i=0;
for(int i=0;i<s.length();i++){
if(s[i]== ‘a’ || s[i]==‘A’|| s[i]==‘e’ || s[i]==‘E’ || s[i]==‘i’ || s[i]==‘I’ || s[i]==‘o’ || s[i]==‘O’ || s[i]==‘u’ || s[i]==‘U’)
vowcnt++;

else conscnt++;
}  
cout<<vowcnt<<" "<<conscnt;

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}