Skip to content

Commit 23f54da

Browse files
authored
Create 04 Reverse the vowels.cpp
1 parent 8563aa3 commit 23f54da

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Diff for: String/problem on string/04 Reverse the vowels.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
bool isVowel(char c)
4+
{
5+
return (c=='a' || c=='A' || c=='e' ||
6+
c=='E' || c=='i' || c=='I' ||
7+
c=='o' || c=='O' || c=='u' ||
8+
c=='U');
9+
}
10+
string reverseVowel(string str)
11+
{
12+
int j=0;
13+
string vowel;
14+
for (int i=0; str[i]!='\0'; i++)
15+
if (isVowel(str[i]))
16+
vowel[j++] = str[i];
17+
for (int i=0; str[i]!='\0'; i++)
18+
if (isVowel(str[i]))
19+
str[i] = vowel[--j] ;
20+
21+
return str;
22+
}
23+
int main()
24+
{
25+
string str;
26+
cin>>str;
27+
cout << reverseVowel(str);
28+
return 0;
29+
}

0 commit comments

Comments
 (0)