C语言对字符串中的字符按照字母顺序和数字顺序重新排列?

优先级为
大写字母>小写字母>数字

第1个回答  2019-10-06
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<string>
int main(){
char s[100],C[100],c[100],n[100],rC=0,rc=0,rn=0;
scanf("%s",s);
int lenth=strlen(s);
std::sort(s,s+lenth);
for(int i=0;i<lenth;++i){
if(s[i]>='0' and s[i]<='9')
n[rn++]=s[i];
else if(s[i]>='a' and s[i]<='z')
c[rc++]=s[i];
else if(s[i]>='A' and s[i]<='Z')
C[rC++]=s[i];
}
n[rn++]='\0';
c[rc++]='\0';
C[rC++]='\0';
printf("%s%s%s",C,c,n);
}追问

能用C吗,我刚入门,库的话尽量只用, 函数自己写,还有优先级不对呀?

追答

#include
#include
#include
#include
int main(){
char s[100],C[100],c[100],n[100],rC=0,rc=0,rn=0;
scanf("%s",s);
int lenth=strlen(s);
std::sort(s,s+lenth);
for(int i=0;i='0' and s[i]='a' and s[i]='A' and s[i]<='Z')
C[rC++]=s[i];
}
n[rn++]='\0';
c[rc++]='\0';
C[rC++]='\0';
printf("%s%s%s",C,c,n);
}

本回答被提问者采纳
相似回答