PREV-5 错误票据

来源:互联网 发布:云计算是什么意思啊 编辑:程序博客网 时间:2024/06/06 04:20

题目:

这里写图片描述

import java.util.*;public class Main{    public static void main(String[] args) {        Scanner read = new Scanner(System.in);        String n = read.nextLine();        List<Integer> list = new ArrayList<>();        int num1 = 0;        int num2 = 0;        for (int i = 0; i < Integer.valueOf(n); i++) {            String str = read.nextLine();            String[] array = str.trim().split("\\s+");            for (int j = 0;j < array.length; j++){                list.add(Integer.valueOf(array[j]));            }        }        Collections.sort(list);        for(int i = 0;i< list.size()-1 ; i++){            if(list.get(i)+1 == list.get(i+1)+1){                num1 = list.get(i);            }            if(list.get(i) + 2 == list.get(i+1) ){                num2 = list.get(i) + 1;            }        }        System.out.println(num2 +" " +num1);    }}