Basics of Implementation – Hackerearth

Vowel count in a string:
code:

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a=0,e=0,i=0,o=0,u=0;
    string s;
    cin>>s;
    int len=s.length();
    for(int j=0;j<len;j++)
    {
        if(s[j]=='a')
        {
            a++;
        }
        else if(s[j]=='e')
        {
            e++;
        }
        else if(s[j]=='i')
        {
            i++;
        }
        else if(s[j]=='o')
        {
            o++;
        }
        else if(s[j]=='u')
        {
            u++;
        }
    }

    cout<<"a "<<a<<endl;
    cout<<"e "<<e<<endl;
    cout<<"i "<<i<<endl;
    cout<<"o "<<o<<endl;
    cout<<"u "<<u<<endl;

}

Count Digit:

#include<iostream>
using namespace std;
int main()
{
    int zero=0,one=0,two=0,three=0,four=0,five=0,six=0,seven=0,eight=0,nine=0;
    string s;
    cin>>s;
    int len=s.length();
    for(int i=0;i<len;i++){
        if(s[i]=='0'){
            zero++;
        }
        else if(s[i]=='1'){
            one++;
        }
        else if(s[i]=='2'){
            two++;
        }
        else if(s[i]=='3')
        {
            three++;
        }
        else if(s[i]=='4'){
            four++;
        }
        else if(s[i]=='5')
        {
            five++;
        }
        else if(s[i]=='6'){
            six++;
        }
        else if(s[i]=='7'){
            seven++;
        }
        else if(s[i]=='8'){
            eight++;
        }
        else if(s[i]=='9')
        {
            nine++;
        }
    }
    cout<<"0 "<<zero<<endl;
    cout<<"1 "<<one<<endl;
    cout<<"2 "<<two<<endl;
    cout<<"3 "<<three<<endl;
    cout<<"4 "<<four<<endl;
    cout<<"5 "<<five<<endl;
    cout<<"6 "<<six<<endl;
    cout<<"7 "<<seven<<endl;
    cout<<"8 "<<eight<<endl;
    cout<<"9 "<<nine<<endl;

    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.