#include <iostream>
using namespace std;
void paixu(char *string, int length)
{
char temper;
int i,j;
if (string == NULL || length <2)
return;
for (i = 1; i < length; i++)
{
for (j = 0; j < length-i; j++)
{
if (string[j] > string[j+1])
{
temper = string[j];
string[j] = string[j+1];
string[j+1] = temper;
}
}
}
cout<<string<<endl;
}
void delete_(char* string, int length)
{
if (string == NULL || length < 2)
return;
char *s = new char[length+1]; //若字符串中无重复字符,则s需要length+1的空间
int j = 0;
s[0] = string[0];
for (int i = 0; i < length; i++)
{
if (string[i] != string[i+1])
{
j++;
s[j] = string[i+1]; //若字符串中无重复字符,则s需要(length+1)*sizeof(char)的空间,string末尾的'\0'也被输入到s
}
}
strcpy(string,s);
cout<<string<<endl;
delete[] s
题目:剔除一个字符中重复的字符,然后按ASCII码值从小到大排列。 例如,输入:abbcccddeeeffgghh 输出:abcdefgh 注意:1、剔除是整个字符串中重复的字符,而不是连续的字符 2
最新推荐文章于 2021-12-08 13:55:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)