-
leetcod:链接
-
问题描述:反转字符串中的元音字符(a,e,i,o,u)
-
示例:
Given s = “leetcode”, return “leotcede”. -
c++代码
#include<iostream>
using namespace std;
#include<string>
class Solution
{
private:
string input;
public:
string reverse_vowel(string s)
{
int i = 0;
int j = s.length();
string vowels = "aeiou";
char tmp;
while (i < j)
{
while (i < j)
{
if (vowels.find(s[i]) == string::npos)
++i;
else
break;
}
while (i < j)
{
if (vowels.find(s[j]) == string::npos)
--j;
else
break;
}
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
++i;
--j;
}
return s;
}
};
int main(int argc, char* argv[])
{
Solution solution;
cout << "the reverse vowel is :" << solution.reverse_vowel("leet code") << endl;
system("pause");
}