Dev Skill DCP-584: G-String Solution


Problem Link
Dev Skill DCP-584: G-String Solution
#include<bits/stdc++.h>
using namespace std;
string v="aeiou";
int count(string s)
{
    int l=s.size();
    int vc=0;
    int c=0;
    bool flag=false;
    for(int i=0; i<l; i++)
    {
        if(s[i]>=97 && s[i]<=122)
        {
            flag=false;
            for(int j=0; j<5; j++)
            {
                if(s[i]==v[j])
                {
                    vc++;
                    flag=true;
                    break;
                }
            }
            if(flag==false)
                c++;
        }
    }
    if(vc<=c)
        return vc;
    else
        return c;
}
int con(string s)
{
    int l=s.size();
    int c=0;
    for(int i=0; i<l; i++)
    {
        if(s[i]<'a' || s[i]>'z')
            c++;
    }
    return c;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin.ignore();
        string s;
        cin>>s;
        int ch=0;
        int c=con(s);
        if(c==s.size())
            cout<<s.size()<<endl;
        else
        {
            ch=count(s);
            ch=ch+c;
            cout<<ch<<endl;
        }
    }
    return 0;
}

No comments

Theme images by enjoynz. Powered by Blogger.