문자열 하나를 받고 해당 문자열에서 모음들만의 순서를 거꾸로 하는 문자열을 만드는 문제
class Solution {
public:
string reverseVowels(string s) {
bool headReady{false};
bool tailReady{false};
int head = 0;
int tail = s.size() - 1;
while (head < tail)
{
switch(s[head])
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
headReady = true;
break;
default:
head++;
break;
}
switch(s[tail])
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
tailReady = true;
break;
default:
tail--;
break;
}
if (headReady && tailReady)
{
headReady = false;
tailReady = false;
swap(s[head++], s[tail--]);
}
}
return s;
}
};