"CCF" opposite number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.