版本号排序

题目

输入一行,输出最小版本

示例

输入 2.4 2.10.3 5.4.6 7.6.5.4 3.2.12.12 1.4.5 1.10.8
输出 1.4.5

输入 5.6.7 4.3.1 7.8.4 5.10 3.4.4.4 3.4 4.7.0
输出 3.4

思路

先对输入的各个版本号进行排序,Arrays.sort();
第一位版本号的第一个数字,是最小版本的首位数字,据此可以排除一些不必要的循环判断。
对于首位相同的版本号,进行第二位以及其余位的判断。

代码

import java.util.*;

public class Main {


    public static void main(String[] args) {
       Scanner in =new Scanner(System.in);
       while(in.hasNext()) {
           String str = in.nextLine();
           String[] split = str.split("\\s");
           // 字典序排列  从小到大
           Arrays.sort(split);
           // 最小版本起始
           int min = Integer.parseInt(split[0].split("\\.")[0]);
           int index = 0;
           for(int i=0;i Integer.parseInt(list2[i])){
                return false;
            }
        }
        if(list1.length <= list2.length) {
            return true;
        }else {
            return false;
        }
    }
}

版本号排序_第1张图片

转载于:https://www.cnblogs.com/lick468/p/11441589.html

你可能感兴趣的:(版本号排序)