日期:2014-05-20 浏览次数:20822 次
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
String line;
while ((line=scanner.nextLine())!=null&&line.length()>0) {
String[] nums=line.split("5");
List<Integer> list=new LinkedList<Integer>();
for (String num : nums) {
if (num.length()==0) {
//防止连续出现5
continue;
}
list.add(Integer.valueOf(num));
}
Collections.sort(list);
for (Integer integer : list) {
System.out.print(integer);
System.out.print(" ");
}
System.out.println();
}
scanner.close();
}
import java.util.*;
public class SplitByToken {
private static final String SPLIT_TOKEN_IN = "5";
private static final String SPLIT_TOKEN_OUT = " ";
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
String scannerNextLine = "";
while ((scannerNextLine = scanner.nextLine()) != null && scannerNextLine.length() > 0) {
String[] splitStringArray = scannerNextLine.split(SPLIT_TOKEN_IN);
SortedSet<String> splitStringSortedSet = new TreeSet<String>();
for (String splitString : splitStringArray) {
splitStringSortedSet.add(splitString);
}
String printString = "";
for (String splitString : splitStringSortedSet) {
printString = printString.concat(Integer.valueOf(splitString) + SPLIT_TOKEN_OUT);
}
System.out.println(printString.trim());
}
scanner.close();
} catch (Exception e) {
System.out.println(e);
} finally {
}
}
}