[CCF CSP]201403-1 相反数

简单题 细心最重要,多自测几组数据,静态查错保证正确率

#include<bits/stdc++.h>
using namespace std;
int a[2005]={0};
int main()
{
    int n,cnt=0;
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0,k;i<n;i++){
        cin>>k;
        if(k<0)
        {
            if(a[-k]) cnt++;
            a[k+1000]=1;
        }
        else{
            if(a[-k+1000]) cnt++;
            a[k]=1;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Andrew-aq/p/12439359.html