字符串排序(3)
字符串排序(3)
http://www.nowcoder.com/questionTerminal/0588d343472e42a9af1eda9a69912df3
import java.util.ArrayList; import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); String a; while(s.hasNext()) { a = s.next(); String[] strs = a.split(","); ArrayList<String> record = new ArrayList<>(); for (String str : strs) { for (int j = 0; j < record.size() + 1; j++) { if (j == record.size()) { record.add(str); break; } if (record.get(j).compareTo(str) > 0) { record.add(j, str); break; } } } for (int i = 0; i<record.size();i++) { if(i==record.size()-1)System.out.print(record.get(i)); else System.out.print(record.get(i)+","); } System.out.println(""); } } }