CSP201403-1: reverse number, csp201403-1 reverse number

Source: Internet
Author: User

CSP201403-1: reverse number, csp201403-1 reverse number

Introduction:CSP (http://www.cspro.org/lead/application/ccf/login.jsp) is a "Computer vocational qualification certification" examination initiated by CCF, perform capability certification for professionals in computer software development, software testing, information management, and other fields. The subjects of certification are those who are engaged in or will be engaged in IT professional technical and technical management personnel, as well as review subjects for university recruitment and postgraduate students.

 

  • Problem description

There are N non-zero and different integers. Compile a program to find the number of pairs of the opposite numbers (a and-a are a pair of opposite numbers ).

  • Input Format

The first line contains a positive integer N. (1≤n ≤500 ).

The second behavior is N non-zero integers separated by a single space. The absolute value of each number cannot exceed 1000, so that these integers are different.

  • Output Format

Only one integer is output, that is, the number of pairs in the N number.

  • Sample Input

5

1 2 3-1-2

  • Sample output

2

 

  • Source code

# Include <stdio. h>

# Include <stdlib. h>

# Include <memory. h>

 

Int main (void)

{

Int n; // number

Scanf ("% d", & n );

Int result = 0;

Int * input = (int *) malloc (sizeof (int) * n );

Memset (input, 0, sizeof (int) * n );

For (int I = 0; I <n; I ++)

{

Scanf ("% d", input + I );

}

For (int I = 0; I <n; I ++)

{

For (int j = I + 1; j <n; j ++)

{

If (input [I] + input [j] = 0)

{

Result + = 1;

}

}

}

Printf ("% d \ n", result );

Free (input );

Return 0;

}

Related Article

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.