天天看點

csp認證題目中相反數

csp認證題目中相反數

基本思想:

相反數就是兩個數和為0,用最簡單粗暴方法就是利用兩個循環使一個數和剩下所有數相加,如果和為0,相反數個數加一。

csp認證題目中相反數

n=int(input())

m=[]

count=0

m=list(map(int,input().split()))

for i in range(n):

for j in range(i+1,n):

temp=m[i]+m[j]

if temp==0:

count+=1

print(count)