-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort_vowel_in_string.cpp
More file actions
58 lines (46 loc) · 1.14 KB
/
Sort_vowel_in_string.cpp
File metadata and controls
58 lines (46 loc) · 1.14 KB
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
52
53
54
55
56
57
58
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
string s;
cout << "Enter String: " << endl;
cin >> s;
vector<int> lower(26,0);
vector<int> upper(26,0);
for(int i=0; i<s.size(); i++) {
if(s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U'){
upper[s[i] - 'A']++;
s[i] = '#';
}
else if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'){
lower[s[i] - 'a']++;
s[i] = '#';
}
}
string ans;
for(int i=0; i<26; i++) {
char c = 'A'+ i;
while(upper[i]){
ans += c;
upper[i]--;
}
}
for(int i=0; i<26; i++) {
char c = 'a'+ i;
while(lower[i]) {
ans += c;
lower[i]--;
}
}
int second = 0;
int first = 0;
while(second < ans.size() && first<s.size()) {
if(s[first] == '#') {
s[first] = ans[second];
second++;
}
first++;
}
cout << s << " ";
}