0
点赞
收藏
分享

微信扫一扫

python 运用pandas 库处理excel 表格数据

小铺有酒一两不够 2023-12-08 阅读 22

在无序的N串数字中找多重复和缺少的数------读取数据后排序找

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
    static int n;   //表示有多少个数
    static int cnt; //表示有多少行
    static int[] data = new int[110];   //存储数据
    static BufferedReader in = new BufferedReader(
            new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        cnt = Integer.parseInt(in.readLine());
        while (cnt-- > 0){
            String[] init = in.readLine().split(" ");
            for (int i = 0; i < init.length; i++) {
                data[n++] = Integer.parseInt(init[i]);
            }
        }
        
        int res1 = 0;
        int res2 = 0;
        Arrays.sort(data,0,n);
        for (int i = 0; i < n - 1; i++) {
            if (data[i + 1] - data[i] == 2) res1 = data[i] + 1;
            else if(data[i + 1] == data[i]) res2 = data[i];
        }
        System.out.println(res1 + " " + res2);
    }
}
举报

相关推荐

0 条评论