将一个字符串的元音字母复制到另一个字符串,并排序

问题描述:

有一字符串,里面可能包含英文字母(大写、小写)、数字、特殊字符,现在需要实现一函数,将此字符串中的元音字母挑选出来,存入另一个字符串中,并对字符串中的字母进行从小到大的排序(小写的元音字母在前,大写的元音字母在后,依次有序)。

说明

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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值