输入一个字符串,将字符串中的字母所有字符按ASCII码升序排列后输出。

用c语言表编写

第1个回答  推荐于2017-11-23
#include <stdio.h>

int main()
{
char ch;
char s[300];
int i,t[300];
scanf("%s",s);
for (i=0;i<256;i++) t[i]=0;
i=0;
while (s[i]) t[s[i++]]++;
for (i=0;i<256;i++)
while (t[i]--)
putchar(i);
putchar('\n');
//scanf("%s",s);这句话注视下,~~ 为了看结果多打的一句话~~
return 0;
}本回答被网友采纳
第2个回答  2010-06-10
#include "stdio.h"
#include "stdlib.h"
int cmp_char(const void *_a,const void *_b)
{
return *(char *)_a-*(char *)_b;
}
int main()
{
char buf[10000];
scanf("%s",buf);
qsort(buf,strlen(buf),sizeof(char),cmp_char);
printf("%s\n",buf);
return 0;
}
//这是用快速排序做的

参考资料:自己写的

第3个回答  2010-06-10
这就是一个排序问题嘛
相似回答