-
Notifications
You must be signed in to change notification settings - Fork 71
/
reversing-the-vowels.cpp
51 lines (47 loc) · 1.16 KB
/
reversing-the-vowels.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// https://practice.geeksforgeeks.org/problems/reversing-the-vowels/0/?problemStatus=unsolved&difficulty[]=-2&page=1&sortBy=submissions&query=problemStatusunsolveddifficulty[]-2page1sortBysubmissions
#include <bits/stdc++.h>
using namespace std;
bool is_vowel[CHAR_MAX] = { false }; // initializes all values to false
void InitializeVowels(string set_of_patterns)
{
for(int i =0; i < set_of_patterns.size(); i++)
{
is_vowel[(int)set_of_patterns[i]] = true;
}
}
string ReverseVowels(string word)
{
string vowels = "";
int len = word.size();
for(int i =0; i< len; i++)
{
if(is_vowel[(int)word[i]])
vowels += word[i];
}
reverse(vowels.begin(), vowels.end());
int start = 0;
for(int i =0; i < len; i++)
{
if(is_vowel[(int)word[i]])
{
word[i] = vowels[start];
start++;
}
}
return word;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
InitializeVowels("aeiouAEIOU");
long int t;
cin >>t;
while(t--)
{
string word;
cin >> word;
cout << ReverseVowels(word) <<endl;
}
return 0;
}