正文

分类排序2008-03-23 13:17:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/zhaoyg/33522.html

分享到:

/*
题目描述:
编写一个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 20
int 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;
}

阅读(2547) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册