1086: ASCII碼排序(多實例測試)
時間限制: 1 Sec 內存限制: 128 MB
提交: 49288 解決: 6360
[提交] [狀態] [討論版] [命題人:admin]
題目描述
輸入三個字符後,按各字符的ASCII碼從小到大的順序輸出這三個字符。
輸入
輸入數據有多組,每組佔一行,有三個字符組成,之間無空格。
輸出
對於每組輸入數據,輸出一行,字符中間用一個空格分開。
樣例輸入 Copy
qwe asd zxc
樣例輸出 Copy
e q w a d s c x z
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
char []ch=new char [10];
// int num1=sc.nextInt();
// int num2=sc.nextInt();
String s;
while(sc.hasNext())
{
s=sc.next();
// if(s.charAt(0))
for(int i=0;i<3;i++)
{
ch[i]=s.charAt(i);
}
for(int i=2;i>=0;i--)
{
for(int j=0;j<i;j++)
{
if(ch[j]>ch[j+1])
{
char ds=ch[j];
ch[j]=ch[j+1];
ch[j+1]=ds;
}
}
}
for(int i=0;i<3;i++)
{
if(i!=2)
System.out.printf("%c ",ch[i]);
else
System.out.printf("%c\n",ch[i]);
}
// System.out.printf("\n");
}
// in.close();
}
}
/*
3 2 1
3 2 1
*/