注意的点
差为0的统计 (测试点1 2)
实现
#include <iostream>
using namespace std;
int main()
{
int i, N,temp,count[10001] = {0}; //count用来记录各种差值的出现次数
cin >> N;
for (i = 0; i < N; i++)
{
cin >> temp;
temp = temp >= (i+1) ? temp - (i+1) : (i+1) - temp;
count[temp]++;
}
for (i = 10001; i >=0; i--)
{
if (count[i] >= 2)
cout << i << " " << count[i] << endl;
}
return 0;
}