-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2785.cpp
More file actions
35 lines (32 loc) · 841 Bytes
/
2785.cpp
File metadata and controls
35 lines (32 loc) · 841 Bytes
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
#include <bits/stdc++.h>
using namespace std;
string sortVowels(string s)
{
vector<char> vowels;
vector <bool> flag;
for (auto i = 0; i <= s.length(); i++) {
flag.push_back(0);
}
for (auto i = 0; i < s.length(); i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U') {
vowels.push_back(s[i]);
flag[i] = 1;
}
}
sort(vowels.begin(), vowels.end());
string res = "";
for (auto i = 0; i < s.length(); i++) {
if (flag[i]) {
res += vowels[0];
vowels.erase(vowels.begin());
} else {
res += s[i];
}
}
return res;
}
int main()
{
string s = "lEetcOde";
cout << sortVowels(s) << endl;
}