Computer Science, asked by pinky9335, 6 months ago

Take a single line text message from user. Separate
the vowels from the text. Find the repeating
occurrences of vowels from the text message
Display count of which vowel has repeated how many
times
Display a new Text message by removing the vowel
characters as output
Display the output in exact format shown below in
example, after displaying count of characters on ner
lines display the new text message on next line
"HII wiem" is the new text message
If text message entered by user does not contain any
vowels then display as output.
If text message entered by user contain any numer
value then display as output.
If User enters blank or empty text message seun
INVALID INPUT" as output. Message WNWALID ARU
is case sensitive Display it in exact formance
Example
Hello welcome
Onun what is the code in c language

Answers

Answered by ammarkheroda21
0

what is this this is not at a pranking app

Answered by parthu2011
1

Answer:

Given a string of length N of lowercase characters containing 0 or more vowels, the task is to find the count of vowels that occurred in all the substrings of the given string.

Examples:

Input: str = “abc”

Output: 3

The given string “abc” contains only one vowel = ‘a’

Substrings of “abc” are = {“a”, “b”, “c”, “ab”, “bc, “abc”}

Hence, the sum of occurrences of the vowel in these strings = 3.(‘a’ occurred 3 times)

Input: str = “daceh”

Output: 16

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Naive Approach: Given a string of length N, the number of substrings that can be formed=N(N+1)/2. A simple solution is for each substring, we count the occurrences of the vowels and add them to get the result. The time complexity of this approach is O(N3) which is not suitable for large values of N.

Efficient Approach: The idea is to use a prefix sum array-based technique where we store the occurrences of each character in all the substrings concatenated.

For the first character,

no. of occurrences = no. of substrings starting with the first character = N.

For each of the following characters, we store the

no. of substrings starting with that character + the number of substrings formed by the previous characters containing this character – the number of substrings formed by the previous characters only.

Below is the implementation of the above approach:

filter_none

edit

play_arrow

brightness_4

// C++ implementation of the above approach  

#include <bits/stdc++.h>  

using namespace std;  

 

// Returns the total sum of  

// occurrences of all vowels  

int vowel_calc(string s)  

{  

   int n = s.length();  

   vector<int> arr;  

 

   for (int i = 0; i < n; i++) {  

 

       if (i == 0)  

           // No. of occurrences of 0th character  

           // in all the substrings  

           arr.push_back(n);  

 

       else

           // No. of occurrences of the ith character  

           // in all the substrings  

           arr.push_back((n - i) + arr[i - 1] - i);  

   }  

 

   int sum = 0;  

   for (int i = 0; i < n; i++)  

 

       // Check if ith character is a vowel  

       if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i'

           || s[i] == 'o' || s[i] == 'u')  

           sum += arr[i];  

 

   // Return the total sum  

   // of occurrences of vowels  

   return sum;  

}  

 

// Driver code  

int main()  

{  

   string s = "daceh";  

   cout << vowel_calc(s) << endl;  

 

   return 0;  

}  

Output:

16

Explanation:

if you are pleased with answer in turn

please subscribe my youtube chanel(Ramakrishna Nallangari youtube channel) for my effort

search for  

Ramakrishna Nallangari in search box

of youtube

Similar questions