Little Monk and Good String

QUESTION

Little monk loves good string. Good String is a string that only contains vowels \n(a,e,i,o,u). Now, his teacher gave him a string S. Little monk is wondering what is the length of the longest good string which is a substring of S.\n\nNote: Strings contains only lower case English Alphabets.\n\nInput:\nFirst line contains a string S,\n(1|S|10^5), where \n|S| denotes the length of the string.\n\nOutput:\nPrint an integer denoting the length of the longest good substring, that is substring consists of only vowels.

ANSWER

#include <iostream>
#include <cstdio>
using namespace std;
string s1 = "aeiou";
bool isVowel(char c)
{
    for(int i = 0;i < 5;i++)
        if(c == s1[i])
            return true;
    return false;
}
int main(int argc, char *argv[])
{
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    int n, y, cnt, ans;
    string s;
    cin >> s;
    n = s.length();
    ans = 0;
    for(int i = 0;i < n;++i)
    {
        if(isVowel(s[i]))
        {
            y = i;
            cnt = 0;
            while(y < n and isVowel(s[y]))
            {
                cnt++;
                y++;
            }
            i = y-1;
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.