文章
6
粉丝
125
获赞
20
访问
1.7k
#include<bits/stdc++.h>
using namespace std ;
bool cmp (char c, char b) //这串代码是为了将字符串中的大写字母转换成小写统一进行排序比较
{
if(c>='A'&&c<='Z')c=c+32;
if(b>='A'&&b<='Z')b=b+32;
return c<b;
}
int main()
{
char s[100];//原始字符串 包括空格之类的
char c[100];//要进行排序的只含字母的字符串
int j=0;
gets(s);
for(int i=0;i<strlen(s);i++)
{
if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))
{
c[j++]=s[i];
}
}
stable_sort(c,c+j,cmp); //规则2要求我们要使用稳定的排序
j=0;
for(int i=0;i<strlen(s);i++)
{
...
登录后发布评论
暂无评论,来抢沙发