水题 * 3 。
#include <bits/stdc++.h> using namespace std; int main() { int n; map<int, int> ans; cin >> n; for(int front = 1; front <= n; front++){ int contrary; cin >> contrary; // 计算并存入数组 ans[abs(front - contrary)]++; } for(auto a = ans.rbegin(); a != ans.rend(); a++) if(a->second > 1) cout << a->first << " " << a->second << endl; }