zoukankan      html  css  js  c++  java
  • tableau OA Aloha8


    import
    java.util.*; public class MyClass { public static void main(String args[]) { String inputString = "1:4 , 5:10,11:20 "; //String inputString = "1:2,5:10"; String[] inputStringArray = inputString.split("\s*,\s*"); int[][] intervals = new int[inputStringArray.length][2]; for (int i = 0; i < intervals.length; i++) { String s = inputStringArray[i]; intervals[i][0] = Integer.valueOf(s.split(":")[0].trim()); System.out.println("intervals[i][0] = " + intervals[i][0]); intervals[i][1] = Integer.valueOf(s.split(":")[1].trim()); System.out.println("intervals[i][1] = " + intervals[i][1]); } int[][] res = merge(intervals); StringBuilder sb = new StringBuilder(); for (int i=0;i <res.length; i++) { sb.append(String.valueOf(res[i][0])); sb.append(":"); sb.append(String.valueOf(res[i][1])); sb.append(","); } //最后输出也要是string String str = sb.toString(); System.out.println(str.substring(0, str.length() - 1)); } public static int[][] merge(int[][] intervals) { if (intervals.length <= 1) return intervals; // Sort by ascending starting point Arrays.sort(intervals, (i1, i2) -> Integer.compare(i1[0], i2[0])); List<int[]> result = new ArrayList<>(); int[] newInterval = intervals[0]; result.add(newInterval); //距离是1也要改 for (int[] interval : intervals) { if (interval[0] <= newInterval[1] + 1) // Overlapping intervals, move the end if needed newInterval[1] = Math.max(newInterval[1], interval[1]); else { // Disjoint intervals, add the new interval to the list newInterval = interval; result.add(newInterval); } } return result.toArray(new int[result.size()][]); } }

    NEXT是一个单词 NEXTLINE是一整行
    system.exit(0) 不打印
    BigInteger要用compareTo,add(new BigInteger("1"))

     

  • 相关阅读:
    PCB 铺铜 转载
    VC++ 学习笔记3 获取编辑框字符串
    VC++ 学习笔记2 列表框添加字符串
    VC++组合框——学习笔记1(组合框选项的添加和无法显示下拉选项)
    微信蓝牙ble记录
    最近遇到的问题与分析还有可能的结果
    注入与以往的开发思路
    abp的权限与导航菜单的关系
    ionic入坑记记录
    abp相关
  • 原文地址:https://www.cnblogs.com/immiao0319/p/15361393.html
Copyright © 2011-2022 走看看