字符串排序(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("");
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
10-05 10:13
已编辑
HHHHaos:让这些老登来现在秋招一下,简历都过不去
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务