/*题目描述:编写一个StrSort函数,要求声明为int StrSort(char str[]);功能是把传入的str参数里的字符串ASCII大小进行升序排序,排序后的结果保存回str中。要求是对数字、小写字母、大写字母分别排序,其它符号位置不变,并且原来是数字的位置排序后还得是数字,原来是小写字母的排序后还得是小写字母 输入:按参数传递,传递的字符串最大串长是1000000个字符 输出:按参数返回,相应原字符串即可函数执行成功则应当返回非0值 样例输入:a5b4c3!d@c#B$A% 样例输出:a3b4c5!c@d#A$B% 07.11.9 zhaoyg*/ #include<stdio.h>#include<conio.h>#include <string.h>#define M 20int StrSort(char *);int main(){ char input[]="dje873hf/*6-4*fsjd83%#KHDS6f8hkldfjs83*fdjdk238sdhj"; //gets(input); StrSort(input); puts(input); getch(); return 0;} int StrSort(char a[ ]){ int i,j,lengh; char temp; for (lengh=0;a[lengh];lengh++) ; //lengh--; for (i=0;i<lengh;i++) for (j=0;j<=lengh;j++) if (((a[i ]<='z' && a[i ]>='a')&&(a[j ]<='z' && a[ j]>='a'))|| ((a[i ]<='9' && a[i ]>='0')&&(a[j ]<='9' && a[j ]>='0'))|| ((a[i ]<='Z' && a[i ]>='A')&&(a[j ]<='Z' && a[ j]>='A')) ) if (a[ i ]<a[j ]) { temp=a[ i]; a[i ]=a[j ]; a[ j]=temp; } return 1;}

评论