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.
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 ).
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.
Only one integer is output, that is, the number of pairs in the N number.
5
1 2 3-1-2
2
# 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; } |