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
  • 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

SAMPLE INPUT
3
6
bazeci
3
abu
1
o
SAMPLE OUTPUT
3
1
0

















In C -



  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5. int test,n,j,i,m,l1=0,l2=0,flag=0;
  6. char str[1000000];
  7. char c[30]={'b','c','d','f','g','h','j','k','l',
  8. 'm','n','p','q','r','s','t','v','w','x','y','z'};
  9. char v[5]={'a','e','i','o','u'};
  10. scanf("%d\n",&test);
  11. for(j=0;j<test;j++)
  12. {
  13. flag=0;
  14. scanf("%d\n",&n);
  15. scanf("%s",&str);
  16. for(i=0;i<n;i++)
  17. {
  18. l1=0,l2=0;
  19. for(m=0;m<21;m++)
  20. {
  21. if(str[i]==c[m])
  22. l1=1;
  23. else
  24. continue;
  25. }
  26. for(m=0;m<5;m++)
  27. {
  28. if(str[i+1]==v[m])
  29. l2=1;
  30. else
  31. continue;
  32. }
  33. if(l1==1 && l2==1)
  34. flag+=1;
  35. }
  36. printf("%d\n",flag);
  37. }
  38. }

      
                                 by - md irfan 


In java



  1. import java.io.*;
  2. public class VCPairs {
  3. public static void main(String[] args) throws IOException {
  4. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  5. int t = Integer.parseInt(br.readLine());
  6. while(t>0) {
  7. int len = Integer.parseInt(br.readLine());
  8. int count = 0;
  9. char[] arr = br.readLine().toCharArray();
  10. for (int i = 0; i<len-1; i++) {
  11. if ((arr[i+1] == 'a' || arr[i+1] == 'e' || arr[i+1] == 'i' ||
  12. arr[i+1] == 'o' || arr[i+1] == 'u') &&
  13. (arr[i] != 'a' && arr[i] != 'e' && arr[i] != 'i' && arr[i] != 'o' && arr[i] != 'u')
  14. ) {
  15. count++;
  16. }
  17. }
  18. System.out.println(count);
  19. t--;
  20. }
  21. br.close();
  22. }
  23. }


                                                                   By -  Abhinav Mukherjee



In Python -


  1. import re
  2. T = int(input())
  3. for _ in range(T) :
  4. n = int(input())
  5. s = input()
  6. print(len(re.findall(r'([^aeiou])([aeiou])',s)))



By - Yash Agrawal



In C++ -


  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int n;
  10. cin>>n;
  11. string s;
  12. cin>>s;
  13. int l=0;
  14. for(int i=0;i<n-1;i++)
  15. {
  16. if((s[i]!='a'&& s[i]!='e'&&s[i]!='i'&&s[i]!='o'&&s[i]!='u')&&(s[i+1]
  17. =='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u'))
  18. l++;
  19.  
  20. }
  21. cout<<l<<endl;
  22. }
  23. return 0;
  24. }


By -  Tanmay Nunhariya


1 Comments

  1. Great website brother. Nice idea to copy paste and post solutions of questions .
    Hindi blog

    ReplyDelete

Post a Comment

Previous Post Next Post