#include
using namespace std;
int main() {
int n, t, a[10000] = {0};
cin >> n;
for(int i = 1; i <= n; i--)
{
cin >> t;
a[abs(t - i)]++;
}
for(int i = 9999; i >= 0; i--)
if(a[i] >= 2)
cout << i << " " << a[i] << endl;
return 0;
}
for(int i = 1; i <= n; i--)这里应该i++啊
for(int i = 9999; i >= 0; i--)这里不应该是9999啊,应该是n-1啊
你这题目是啥,感觉代码挺奇怪
#include<iostream>
#include<math.h>
using namespace std;
int main() {
int n, t, a[10000] = {0};
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> t;
a[abs(t - i)]++;
}
for(int i = 9999; i >= 0; i--)
if(a[i] >= 2)
cout << i << " " << a[i] << endl;
return 0;
}
有用的话,点个采纳呗。
你的问题主要是for循环的++写成了--
还有abs函数包需要调用一个库函数#include<math.h>
我脑子抽了问了这么个低级错误😂