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