Vowel Recognition | Hackerearth practice problem solution
Problem:-
{a,e,i,o,u,A,E,I,O,U}
Natural Language Understanding is the subdomain of Natural Language Processing where people used to design AI based applications have ability to understand the human languages. HashInclude Speech Processing team has a project named Virtual Assistant. For this project they appointed you as a data engineer (who has good knowledge of creating clean datasets by writing efficient code). As a data engineer your first task is to make vowel recognition dataset. In this task you have to find the presence of vowels in all possible substrings of the given string. For each given string you have to print the total number of vowels.
Natural Language Understanding is the subdomain of Natural Language Processing where people used to design AI based applications have ability to understand the human languages. HashInclude Speech Processing team has a project named Virtual Assistant. For this project they appointed you as a data engineer (who has good knowledge of creating clean datasets by writing efficient code). As a data engineer your first task is to make vowel recognition dataset. In this task you have to find the presence of vowels in all possible substrings of the given string. For each given string you have to print the total number of vowels.
Input
First line contains an integer T, denoting the number of test cases.
Each of the next lines contains a string, string contains both lower case and upper case .
Output
Print the vowel sum
Answer for each test case should be printed in a new line.
Input Constraints
1<=T<=10
1<=|S|<=100000
Explanation
First line is number of input string, In given example, string is “baceb” so the substrings will be like -“b, ba, bac, bace, a, ac, ace, aceb, c, ce, ceb, e, eb, baceb” now the number of vowels in each substring will be 0, 1, 1, 2, 1, 1, 2, 2, 0, 1, 1, 1, 1, 2 and the total number will be sum of all presence which is 16.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB
solution:-
#include<stdio.h>
#include<string.h>
int main()
{
int t;
long int sum=0,l;
char s[100000];
scanf(“%d”,&t);
while(t–)
{
scanf(“%s”,s);
l=strlen(s);
for(int i=0;s[i];i++)
{
if(s[i]==‘a’||s[i]==‘e’||s[i]==‘i’||s[i]==‘o’
||s[i]==‘u’||s[i]==‘A’||s[i]==‘E’||s[i]==‘I’||s[i]==‘O’||s[i]==‘U’)
sum=sum+(i+1)*(l–i);
}
printf(“%ldn”,sum);
sum=0;
}
return 0;
}
Recommended post:-
Hackerearth Problems:-
- Very Cool numbers | Hacker earth solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem
Data structure:-
- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree
Key points:-
- How to set limit in the floating value in python
- What is boolean data type
- How to print any character without using format specifier
Must check this:-
..
This comment has been removed by the author.