Instagram
youtube
Facebook
Twitter

Python programme to find the number of indices from the string Codechef solution

Problem:

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

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

Input

  • The first line of the input contains a single integer, T, denoting the number of test cases. The description of T-test cases follows.

  • The first line of each test case contains a single integer, N.

  • The second line contains a single string S with length N.

Output

For each test case, print a single line containing one integer: the number of occurrences of a vowel immediately after a consonant.

Constraints

  • 1<=T<=100

  • 1<=N<=10

Sample Input:

3 
6 
bazeci 
3 
abu 
1 
0

Sample Output: 

3
1
0 

Explanation:

Example case 1: The vowel 'a' follows after the consonant 'b', 'e' follows after 'z, and 'i' follows after 'c', so the answer is 3.

Example case 2: The only vowel 'u' follows after 'b', so the answer is 1.

Solution

t=int(input(“Enter the number of terms: “))
for i in range(t):
    c=0
    x=int(input(“Enter a number: “))
    s=input(“Enter a string: “)
    m=['a','e','i','o','u']
    for j in range(1,len(s)):
        if s[j] in m and s[j-1] not in m:
            c+=1
    print(c)

Steps to solve this problem:

  • Ask the user to enter the number of terms to execute the loop and store it in

  • Initialise a variable with 0.

  • Ask the user to enter a number.

  • Ask the user to enter a string.

  • Make a list of vowels and assign them to

  • In the loop, Check if string characters are present in vowels. If present, increase the value of c by 1.

  • Print the value of c