为了给学弟学妹讲课,我又水了一题……
1: import java.util.*;
2: import java.io.*;
3:4: public class HDU11065: {6: public static void main(String[] args)7: {8: BufferedReader br = new BufferedReader(new InputStreamReader(System.in));9: String s;10: while((s=br.readLine())!=null)11: {12: //去掉字符串中空格,防止useDelimiter连续读取整数出错
13: Scanner sc = new Scanner(s.trim());
14: int k = 0;
15: int a[];
16: a=new int[1001];17: //匹配正则表达式,5+表示匹配一个或多个5,不会产生空字符
18: sc.useDelimiter("5+");
19: while(sc.hasNextInt())
20: a[k++]=sc.nextInt();21: sc.close();22: Arrays.sort(a,0,k);23: for(int i=0;i<k;i++)24: {25: if(i==k-1)
26: System.out.println(a[i]);27: else
28: System.out.print(a[i]+" ");
29: }30: }31: }32: }while(sc.hasNext()) { if(sc.hasNextInt()) { //do sth }else { //直接跳过 next(); } }