问题描述:
测试范例:
有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。
说明
1、 元音字母是 a,e,i,o,u,A,E,I,O,U。
2、 筛选出来的元音字母,不需要剔重(chong);
最终输出的字符串,小写元音字母排在前面,大写元音字母排在后面,依次有序。
#include<iostream>
#include<string.h>
#include<algorithm>
#include<string>
using namespace std;
void SortVowel(char* input, char* output)
{
int len = strlen(input);
char* upper = new char[len+1];
char* lower = new char[len+1];
int u_count = 0;
int l_count = 0;
for (int i = 0; i != len; i++)
{
if (input[i] == 'a' || input[i] == 'e'||input[i] == 'i'||input[i] == 'o'||input[i] == 'u')
{
lower[l_count] = input[i];
l_count++;
}
if (input[i] == 'A' || input[i] == 'E' || input[i] == 'I' || input[i] == 'O' || input[i] == 'U')
{
upper[u_count] = input[i];
u_count++;
}
}
sort(lower, lower+l_count);
sort(upper, upper+u_count);
int i, j=0;
for ( i = 0; i != l_count; i++)
{
output[j] = lower[i];
j++;
}
for ( i = 0; i!= u_count; i++)
{
output[j] = upper[i];
j++;
}
output[j] = '\0';
while (*output!='\0')
{
cout << *output;
output++;
}
delete[] lower;
delete[] upper;
}
测试范例:
“Abort!May Be Some Errors In Out System. “
int main()
{
char *a = "Abort!May Be Some Errors In Out System.";
char *b = new char[strlen(a)];
SortVowel(a, b);
return 0;
}