solution.java 897 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            String s = sc.nextLine();
            String str[] = s.split(" ");
            for (int j = 0; j < str.length; j++) {
                list.add(Integer.parseInt(str[j]));
            }
        }
        Collections.sort(list);
        int m = 0, n = 0;
        for (int i = 0; i < list.size() - 1; i++) {
            if (list.get(i) + 2 == list.get(i + 1))
                m = list.get(i) + 1;
            if (list.get(i).equals(list.get(i + 1)))
                n = list.get(i);
        }
        System.out.println(m + " " + n);
    }
}