Problem Description
Question number: | 201403-1 |
Questions Name: | Opposite number |
time limit: | 1.0s |
Memory Limit: | 256.0MB |
Problem Description: |
Problem Description
There are N non-zero and different integer. You compile a program calculated how many of them there are the opposite of (a and a pair of opposite -a number).
Input Format
The first line contains a positive integer N. (1 ≤ N ≤ 500).
The second line of the N space separated by a single non-zero integer, the absolute value of each number less than 1000, to ensure that these different integers.
Output Format
Output only an integer, i.e., the number of which contains the number N of the opposite number.
Sample input
5
1 2 3 -1 -2
Sample Output
2
|
1 #include<iostream> 2 #include<bits/stdc++.h> 3 using namespace std; 4 #define LL long long 5 int main(){ 6 map<int,int>M; 7 int n,a,ans=0; 8 cin>>n; 9 for(int i=1;i<=n;++i){ 10 cin>>a; 11 M[a]++; 12 if(M[-a])ans++; 13 }cout<<ans<<endl; 14 return 0; 15 }
A map is easy.
-