ASCII码排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142072 Accepted Submission(s): 58350Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。Input输入数据有多组,每组占一行,有三个字符组成,之间无空格。Output对于每组输入数据,输出一行,字符中间用一个空格分开。Sample Inputqwe asd zxc
Sample Outpute q w a d s c x zimport java.util.*; class Main{ public static void main(String[] args){ Scanner sc =new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine();//读取键盘输入的一行数据 char a = str.charAt(0);//拿出第一个字符 char b = str.charAt(1); char c = str.charAt(2); int p,pp; char max=a,min=a;//把最大和最小都赋值<span style="font-family: 'Courier New';">为</span><span style="font-family: 'Courier New';">a</span><span style="font-family: 'Courier New';">字符</span>
<span style="font-family: 'Courier New';"><span style="white-space:pre"> </span>//简单的比较换值</span>
if(b<min)min=b; if(c<min)min=c; System.out.print(min+" "); if(b>max)max=b; if(c>max)max=c; if(a!=max&&a!=min)System.out.print(a+" "); else if(b!=max&&b!=min)System.out.print(b+" "); else if(c!=max&&c!=min)System.out.print(c+" "); System.out.print(max); System.out.println(); } } }
杭电ACM2000题------java语言
最新推荐文章于 2023-03-14 21:18:33 发布