VC Pairs

Max has a string S with length N. He needs to find the number of indices i (1≤i≤N−11≤i≤N−1) such that the i-th character of this string is a consonant and the i+1th character is a vowel. However, she is busy, so she asks for your help.

Note: The letters 'a', 'e', 'i', 'o', 'u' are vowels; all other lowercase English letters are consonants.

Example:

Input:  n = 6, s="bazeci"
Output: 3

Approach

C++

#include <bits/stdc++.h>
using namespace std;

bool isvowel(char c)
{
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        return true;
    return false;
}

int VCPairs(int nstring s)
{
    int cnt = 0;
    for (int i = 0i < n - 1i++)
    {
        if (!isvowel(s[i]) && isvowel(s[i + 1]))
            cnt++;
    }
    return cnt;
}
int main()
{

    int n = 6;
    string s = "bazeci";

    cout << VCPairs(ns<< "\n";

    return 0;
}


No comments:

Post a Comment