PAT_B_1083_Java(20分)

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        String[] s = bf.readLine().split(" ");
        int a[] = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[Math.abs(Integer.parseInt(s[i - 1]) - i)]++;
        }
        for (int j = n - 1; j >= 0; j--) {
            if (a[j] > 1) {
                System.out.println(j + " " + a[j]);
            }
            continue;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43511405/article/details/107430331