Consonants and Vowels check | Practice | GeeksforGeeks

Let's learn about CPP strings here. CPP strings are quite different from their C counterpart and have various methods that can be invoked on them. We hope you've read the articles.
You are given a string s containing only lowercase letters. You need to count the number of vowels and the number of consonants. 
If vowel count > consonant count then print - Yes(without quotes).
If vowel count < consonant count then print - No(without quotes).
If vowel count = consonant count then print - Same(without quotes).
Example 1:
Input:s = "aaaaaa"Output:Yes
Example 2:
Input:s = "the quick brown fox jumps over the lazy dog"Output:No
Your Task:Since this is a function problem, you don't need to take any input. Just complete the function checkString(string s) that take s as input and produces output. In a new line, print the output.
Constraints:1 <= |s| <= 100
0
starrlord3 weeks ago
void checkString(string s)
{
    int v=0;
    int c=0;
    int n=s.length();
    int x=s.length();
    for(int i=0;i<n;i++){
        if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
            v++;
        else if(s[i]==' ')
            x--;
    }
    c=x-v;
    //Your code here
    
    if(v>c)
        cout<<"Yes";
    else if(c>v)
        cout<<"No";
    else
        cout<<"Same";
    
    cout<<endl;
}
0
sahilrawat6801 month ago
// { Driver Code Starts//Initial Template for C++
#include <bits/stdc++.h>using namespace std;
void checkString(string s);
// } Driver Code Ends//User function Template for C++
void checkString(string s){   int v=0;   int c=0;   for(int i=0; i<s.size();i++)   {       if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){       if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){           v++;       }       else{           c++;       }       }   }   //Your code here      if(v>c)       cout<<"Yes";   else if(c>v)       cout<<"No";   else       cout<<"Same";      cout<<endl;}
// { Driver Code Starts.
int main() {int t;cin>>t;cin.ignore();while(t--){        string s;    getline(cin,s);        //function call    checkString(s);   }return 0;}
 // } Driver Code Ends
0
amityadav101 month ago
//what's mistake in this code//
//last case failed// 
int v=0;   int c=0;   int n=s.length();      //Your code here   for(int i=0;i<=n;i++)   {       if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')       {           v=v+1;       }       else       {           c=c+1;       }   }      if(v>c)       cout<<"Yes";   else if(c>v)       cout<<"No";   else       cout<<"Same";      cout<<endl;
0
diptendunandi3 months ago
void checkString(string s)
{
    int v=0;
    int c=0;
    
    //Your code here
    for(int i=0;i<s.length();i++){
    if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){
        if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
        v++;
       
        else
        c++;
    }
    }
    
    if(v>c)
        cout<<"Yes";
    else if(c>v)
        cout<<"No";
    else
        cout<<"Same";
    
    cout<<endl;
}
0
mayank20213 months ago
The catch in this question is the "space" in between characters of string.  This space should be taken into account and should be avoided getting counted both in vowels and consonants.
0
kritigupta70315 months ago
void checkString(string s){   int v=0;   int c=0;      //Your code here   for(int i=0;i<s.length();i++){       if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){       if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' )           v++;               else               c++;             }              }   if(v>c)       cout<<"Yes";   else if(c>v)       cout<<"No";   else       cout<<"Same";      cout<<endl;
}
0
kritigupta7031
This comment was deleted.
0
ayushnautiyal11106 months ago
void checkString(string s){   int v=0;   int c=0;      for(int i=0;i<s.length();i++){       if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u'){           v++;       }       else if(s[i]== ' '){           continue;       }       else{           c++;       }   }      if(v>c)       cout<<"Yes";   else if(c>v)       cout<<"No";   else       cout<<"Same";      cout<<endl;}
0
bawarisuresh1236 months ago
 int v=0;   int c=0;   int i=0;int n=s.size();while(i<n){   if(s[i]!='a'&&s[i]!='e'&&s[i]!='i'&&s[i]!='o'&&s[i]!='u'&&s[i]!='A'&&s[i]!='E'&&s[i]!='I'&&s[i]!='O'&&s[i]!='U'&&s[i]!=' ')   {       c++;       i++;       }   else if(s[i]==' '){       i++;   }   else{   v++;   i++;   }}      if(v>c)       cout<<"Yes";   else if(c>v)       cout<<"No";   else       cout<<"Same";      cout<<endl;}
0
PRJ9 months ago
PRJ
Tip: //EXCLUDE ' ' (space)  
void checkString(string s){    int v=0;    int c=0;
    //Your code here    for(int i=0;i<s.length();i++) {="" if((s[i]="='a'" ||s[i]="='e'" ||s[i]="='i'" ||s[i]="='o'" ||s[i]="='u')" )="" v++;="" else="" if(s[i]!=" " )="" else="" c++;="" }="" cout<<v;="" cout<<c;="" if(v="">c)        cout<<"Yes";    else if(c>v)        cout<<"No";    else if(c==v)        cout<<"Same";
    cout<<endl; }="">
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.