题解 | #图片整理#
图片整理
http://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941
思路:
读取字符串后,按照数字,大写字母,小写字母分类保存在不同的数组。数字数字内排序,大写字母内排序,小写字母内排序。先后输出数字字符串,大写字母字符串,小写字母字符串。
程序:
#include<stdio.h>
#include<string.h>
int main(){
char str[1001]={'\0'};
char shuzi[1001]={'\0'},daxie[1001]={'\0'},xiaoxie[1001]={'\0'};
int i=0,j=0,k=0,end=1000;
int num_shuzi=0,num_daxie=0,num_xiaoxie=0;
scanf("%s",str);
#include<string.h>
int main(){
char str[1001]={'\0'};
char shuzi[1001]={'\0'},daxie[1001]={'\0'},xiaoxie[1001]={'\0'};
int i=0,j=0,k=0,end=1000;
int num_shuzi=0,num_daxie=0,num_xiaoxie=0;
scanf("%s",str);
//按数字,大写字母,小写字母分类保存
for(int m=0;m<strlen(str);m++){
if(str[m]>='0'&&str[m]<='9'){
shuzi[i]=str[m];
i=i+1;
}
else if(str[m]>='A'&&str[m]<='Z'){
daxie[j]=str[m];
j=j+1;
}
else if(str[m]>='a'&&str[m]<='z'){
xiaoxie[k]=str[m];
k=k+1;
}
}
num_shuzi=i;
num_daxie=j;
num_xiaoxie=k;
//数字排序
char bigger1='\0';
for(i=0;i<num_shuzi-1;i++){
for(j=i+1;j<num_shuzi;j++){
if(shuzi[j]<shuzi[i]){
bigger1=shuzi[i];
shuzi[i]=shuzi[j];
shuzi[j]=bigger1;
}
}
}
//大写字母排序
char bigger2='\0';
for(i=0;i<num_daxie-1;i++){
for(j=i+1;j<num_daxie;j++){
if(daxie[j]<daxie[i]){
bigger2=daxie[i];
daxie[i]=daxie[j];
daxie[j]=bigger2;
}
}
}
//小写字母排序
char bigger3='\0';
for(i=0;i<num_xiaoxie-1;i++){
for(j=i+1;j<num_xiaoxie;j++){
if(xiaoxie[j]<xiaoxie[i]){
bigger3=xiaoxie[i];
xiaoxie[i]=xiaoxie[j];
xiaoxie[j]=bigger3;
}
}
}
//输出
printf("%s",&shuzi[0]);
printf("%s",&daxie[0]);
printf("%s",&xiaoxie[0]);
}
for(int m=0;m<strlen(str);m++){
if(str[m]>='0'&&str[m]<='9'){
shuzi[i]=str[m];
i=i+1;
}
else if(str[m]>='A'&&str[m]<='Z'){
daxie[j]=str[m];
j=j+1;
}
else if(str[m]>='a'&&str[m]<='z'){
xiaoxie[k]=str[m];
k=k+1;
}
}
num_shuzi=i;
num_daxie=j;
num_xiaoxie=k;
//数字排序
char bigger1='\0';
for(i=0;i<num_shuzi-1;i++){
for(j=i+1;j<num_shuzi;j++){
if(shuzi[j]<shuzi[i]){
bigger1=shuzi[i];
shuzi[i]=shuzi[j];
shuzi[j]=bigger1;
}
}
}
//大写字母排序
char bigger2='\0';
for(i=0;i<num_daxie-1;i++){
for(j=i+1;j<num_daxie;j++){
if(daxie[j]<daxie[i]){
bigger2=daxie[i];
daxie[i]=daxie[j];
daxie[j]=bigger2;
}
}
}
//小写字母排序
char bigger3='\0';
for(i=0;i<num_xiaoxie-1;i++){
for(j=i+1;j<num_xiaoxie;j++){
if(xiaoxie[j]<xiaoxie[i]){
bigger3=xiaoxie[i];
xiaoxie[i]=xiaoxie[j];
xiaoxie[j]=bigger3;
}
}
}
//输出
printf("%s",&shuzi[0]);
printf("%s",&daxie[0]);
printf("%s",&xiaoxie[0]);
}