ASCII码排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 108285 Accepted Submission(s): 45236
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe asd zxc
Sample Output
e q w a d s c x z
Author
lcy
Source
Recommend
JGShining | We have carefully selected several similar problems for you:
2002
2005
2010
2006
2007
多学点方法
快排:
排序:
普通:
多学点方法
快排:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void *a,const void *b){
return *(char *)a-*(char *)b;
}
int main(){
char a[3];
int i;
memset(a,0,sizeof(a));
while(~scanf("%s",a)){
getchar();
qsort(a,3,sizeof(a[0]),cmp);
printf("%c",a[0]);
for(i=1;i<3;i++)
printf(" %c",a[i]);
printf("\n");
memset(a,0,sizeof(a));
}
return 0;
}
排序:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char ls[4];
while(cin>>ls[0]>>ls[1]>>ls[2])
{
sort(ls,ls+3);cout<<ls[0]<<" "<<ls[1]<<" "<<ls[2]<<endl;
}
return 0;
}
普通:
#include <stdio.h>
int main()
{
char a,b,c,d,x,y,z;
while(scanf("%c%c%c%c",&a,&b,&c,&d) != EOF)
{
x=a<b?a:b;
x=x<c?x:c;
z=a>b?a:b;
z=z>c?z:c;
y=a+b+c-x-z;
printf("%c %c %c\n",x,y,z);
}
}