Most Vowels in Row
Most Vowels in Row
Problem Statement:
The program must accept a character matrix of size NxN as the input. The program must print the row which contains most number of vowels in it. If more than one row has same number of most number vowels then print the last occurring row.
Boundary Condition(s):
1 <= N <= 50
Input Format:
The first line contain N.
The next N lines contain N characters each separated by a space.
Output Format:
The first line contains C characters.
Example Input/Output 1:
Input:
5
G w w t e
H d E o P
Z D H e W
Z l H e A
H o O D e
Output:
H o O D e
Explanation:
The last two rows have 3 vowels.
So the last occurring row with most number of vowels is the last row.
Example Input/Output 2:
Input:
4
w y o o
g g t t
t o e t
a q r q
Output:
t o e t
Note:
Max Execution Time Limit: 4000 millisecs
Solution:
Programming Language: C Language
#include <stdio.h> #include <stdlib.h> int main(){ int n;scanf("%d",&n); char a[n][n],b[2]; int mvc=0,mvr=0; for(int i=0;i<n;i++){ int cvc=0; for(int j=0;j<n;j++){ scanf("%s",b); a[i][j]=b[0]; switch(tolower(a[i][j])){ case 'a': case 'e': case 'i': case 'o': case 'u': cvc++; } } if(cvc>=mvc){ mvc=cvc; mvr=i; } } for(int j=0;j<n;j++){ printf("%c ",a[mvr][j]); } }
//Published by PKJCODERS(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments