链接:http://acm.hdu.edu.cn/showproblem.php?pid=2000
ASCII码排序
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe asd zxc
Sample Output
e q w a d s c x z
1
/*
******** hdu 2037 ***********
*/
2 /* ******** 琴心&剑胆 *********** */
3 /* ******** 2011/5/4 *********** */
4
5 #include < stdio.h >
6 #include < string .h >
7 #include < stdlib.h >
8 int cmp( const void * m, const void * n ){
9 return * ( char * )m -* ( char * )n;
10 }
11 main(){
12 char a[ 3 ];
13
14 while ( scanf( " %s " , a ) != EOF ){
15 qsort( a, 3 , sizeof (a[ 0 ]),cmp );
16 int i;
17 for ( i = 0 ;i < 3 ; ++ i ){
18 printf( i == 0 ? " %c " : " %c " ,a[i] );
19 }
20 puts( "" );
21 }
22 }
2 /* ******** 琴心&剑胆 *********** */
3 /* ******** 2011/5/4 *********** */
4
5 #include < stdio.h >
6 #include < string .h >
7 #include < stdlib.h >
8 int cmp( const void * m, const void * n ){
9 return * ( char * )m -* ( char * )n;
10 }
11 main(){
12 char a[ 3 ];
13
14 while ( scanf( " %s " , a ) != EOF ){
15 qsort( a, 3 , sizeof (a[ 0 ]),cmp );
16 int i;
17 for ( i = 0 ;i < 3 ; ++ i ){
18 printf( i == 0 ? " %c " : " %c " ,a[i] );
19 }
20 puts( "" );
21 }
22 }