
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ code to find corrected text after double vowel removal
Suppose we have a string S with n character. On a text editor, there is a strange rule. The word corrector of this text editor works in such a way that as long as there are two consecutive vowels in the word, it deletes the first vowel in a word. If there are no two consecutive vowels in the word, it is considered to be correct. We have to find corrected word from S. Here vowels are 'a', 'e', 'i' 'o', 'u' and 'y'.
So, if the input is like S = "poor", then the output will be "por".
Steps
To solve this, we will follow these steps −
n := size of S t := "aeiouy" for initialize i := 1, when i < n, update (increase i by 1), do: if S[i] is in t and S[i - 1] is in t, then: delete ith character from S (decrease i by 1) return S
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; string solve(string S){ int n = S.size(); string t = "aeiouy"; for (int i = 1; i < n; i++){ if (t.find(S[i]) != -1 && t.find(S[i - 1]) != -1){ S.erase(i, 1); i--; } } return S; } int main(){ string S = "poor"; cout << solve(S) << endl; }
Input
"poor"
Output
por
- Related Articles
- C++ code to find final number after min max removal game
- C++ code to find answers by vowel checking
- C++ Program to find array after removal from maximum
- C++ program to find reduced size of the array after removal operations
- C++ code to find minimal tiredness after meeting
- C++ program to find array after removal of left occurrences of duplicate elements
- C++ code to find xth element after removing numbers
- C++ code to find tree height after n days
- C++ code to find minimum stones after all operations
- C++ code to find position of students after coding contest
- C++ code to find money after buying and selling shares
- C++ code to count volume of given text
- Program to find length of longest contiguously strictly increasing sublist after removal in Python
- C++ program to find winner of ball removal game
- C++ Program to find maximum score of bit removal game

Advertisements