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.
Input
For each test case, print a single line containing one integer ― the number of occurrences of a vowel immediately after a consonant
Note: The letters 'a', 'e', 'i', 'o', '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.
For each test case, print a single line containing one integer ― the number of occurrences of a vowel immediately after a consonant
SAMPLE INPUT
3 6 bazeci 3 abu 1 o
SAMPLE OUTPUT
3 1 0
In C -
- #include<stdio.h>
- int main()
- {
- int test,n,j,i,m,l1=0,l2=0,flag=0;
- char str[1000000];
- char c[30]={'b','c','d','f','g','h','j','k','l',
- 'm','n','p','q','r','s','t','v','w','x','y','z'};
- char v[5]={'a','e','i','o','u'};
- scanf("%d\n",&test);
- for(j=0;j<test;j++)
- {
- flag=0;
- scanf("%d\n",&n);
- scanf("%s",&str);
- for(i=0;i<n;i++)
- {
- l1=0,l2=0;
- for(m=0;m<21;m++)
- {
- if(str[i]==c[m])
- l1=1;
- else
- continue;
- }
- for(m=0;m<5;m++)
- {
- if(str[i+1]==v[m])
- l2=1;
- else
- continue;
- }
- if(l1==1 && l2==1)
- flag+=1;
- }
- printf("%d\n",flag);
- }
- }
by - md irfan
In java
- import java.io.*;
- public class VCPairs {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int t = Integer.parseInt(br.readLine());
- while(t>0) {
- int len = Integer.parseInt(br.readLine());
- int count = 0;
- char[] arr = br.readLine().toCharArray();
- for (int i = 0; i<len-1; i++) {
- if ((arr[i+1] == 'a' || arr[i+1] == 'e' || arr[i+1] == 'i' ||
- arr[i+1] == 'o' || arr[i+1] == 'u') &&
- (arr[i] != 'a' && arr[i] != 'e' && arr[i] != 'i' && arr[i] != 'o' && arr[i] != 'u')
- ) {
- count++;
- }
- }
- System.out.println(count);
- t--;
- }
- br.close();
- }
- }
By - Abhinav Mukherjee
In Python -
- import re
- T = int(input())
- for _ in range(T) :
- n = int(input())
- s = input()
- print(len(re.findall(r'([^aeiou])([aeiou])',s)))
By - Yash Agrawal
In C++ -
- #include<iostream>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- cin>>n;
- string s;
- cin>>s;
- int l=0;
- for(int i=0;i<n-1;i++)
- {
- if((s[i]!='a'&& s[i]!='e'&&s[i]!='i'&&s[i]!='o'&&s[i]!='u')&&(s[i+1]
- =='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u'))
- l++;
- }
- cout<<l<<endl;
- }
- return 0;
- }
By - Tanmay Nunhariya
Great website brother. Nice idea to copy paste and post solutions of questions .
ReplyDeleteHindi blog
Post a Comment