-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ49.cpp
More file actions
38 lines (31 loc) · 759 Bytes
/
Copy pathQ49.cpp
File metadata and controls
38 lines (31 loc) · 759 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
36
37
38
#include <string>
#include <map>
#include <vector>
using namespace std;
int solution(string word) {
char arr[] = {'A', 'E', 'I', 'O', 'U'};
map<char, char> nexts;
nexts['A'] = 'E';
nexts['E'] = 'I';
nexts['I'] = 'O';
nexts['O'] = 'U';
string cur = "A";
int order = 0;
while (cur != word) {
int len = cur.size();
if (len < 5) {
cur += 'A';
order++;
continue;
}
while (cur[cur.size() - 1] == 'U') {
cur = cur.substr(0, cur.size() - 1);
}
if (cur.size() == 0) {
break;
}
cur[cur.size() - 1] = nexts[cur[cur.size() - 1]];
order++;
}
return order + 1;
}