今天与一位acm的牛人交谈,其实是学弟,问到acm入门,他说了句要看天分,然后给了个网站,杭电的acm,第十一页,一个人完成。100道题目,今天开始。
第一道题
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe asd zxc
Sample Output
e q w a d s c x z
import java.util.Scanner;
public class POJ2000 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
String a = cin.nextLine();
char t1 = a.toCharArray()[0];
char t2 = a.toCharArray()[1];
char t3 = a.toCharArray()[2];
char temp;
if (t1 > t2) {
temp = t1;
t1 = t2;
t2 = temp;
}
if (t2 > t3) {
temp = t2;
t2 = t3;
t3 = temp;
if (t1 > t2) {
temp = t1;
t1 = t2;
t2 = temp;
}
}
System.out.println(t1 + " " + t2 + " " + t3 + "\n");
}
}
}