一、题目描述
二、思路
直接暴力遍历即可,当然也可以打表将复杂度降到O(n)
三、代码
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 550;
int A[N], n;
int main () {
cin >> n;
for ( int i = 0; i < n; i++ ) cin >> A[i];
int cnt = 0;
for ( int i = 0; i < n; i++ ) {
for ( int j = i + 1; j < n; j++ ) {
if ( A[i] + A[j] == 0 ) {
cnt++;
}
}
}
cout << cnt;
return 0;
}