Problem description
There are N non-0 integers that are not identical. Please make up a program to find out how many pairs of opposite numbers are in them (a and-A are pairs of opposite numbers).
Input format
The first line consists of a positive integer N. (1≤n≤500).
The second behavior N a non-0 integer separated by a single space, the absolute value of each number does not exceed 1000, guaranteeing that the integers are different.
Output format
Only one integer is output, that is, how many pairs of opposite numbers are included in the N number.
Sample input
5
1 2 3-1-2
Sample output
2
#include <iostream>using namespace STD;intN = +;intm[ +][2];intMain () {memset(M,0, -);intNCin>>n; for(intI=0; i<n;i++) {inttmpCin>>tmp;if(tmp>=0) {m[tmp][0]=1; }Else{m[-tmp][1]=-1; } }intCount=0; for(intI=0;i< +; i++) {if(m[i][0]==1&&m[i][1]==-1) {count++; } }cout<<count<<endl;return 0;}
Just test it yourself, don't know right ... If you have any questions, you are welcome to point out.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"CCF" opposite number