• CCF 201403-1 相反数


    试题编号: 201403-1
    试题名称: 相反数
    时间限制: 1.0s
    内存限制: 256.0MB
    问题描述:
    问题描述
      有 N 个非零且各不相同的整数。请你编一个程序求出它们中有多少对相反数(a 和 -a 为一对相反数)。
    输入格式
      第一行包含一个正整数 N。(1 ≤ N ≤ 500)。
      第二行为 N 个用单个空格隔开的非零整数,每个数的绝对值不超过1000,保证这些整数各不相同。
    输出格式
      只输出一个整数,即这 N 个数中包含多少对相反数。
    样例输入
    5
    1 2 3 -1 -2
    样例输出
    2

    关键词:map键值对

     1 #include<iostream>
     2 #include<map>
     3 #include<cmath>//要包含
     4 using namespace std;
     5 int main(){
     6     //freopen("in2.txt","r",stdin);
     7     int n;
     8     cin >> n;
     9     map<int,int> m;
    10     for(int i = 0;i<n;i++){
    11         int buf;
    12         cin >> buf;
    13         m[abs(buf)]++;
    14     }
    15     int total = 0;
    16     for(map<int,int>::iterator it = m.begin();it!=m.end();it++){
    17         if(it->second > 1){
    18             total++;
    19         }
    20     }
    21     cout << total;
    22     return 0;
    23 }
  • 相关阅读:
    k8s蓝绿
    nginx总结
    promethues监控 之 TCP连接数
    制作私有ssl证书
    redis命令
    zabbix主机自动发现
    Kubernetes各组件服务重启
    linxu下常用命令
    encodeURIComponent
    查询条件
  • 原文地址:https://www.cnblogs.com/ywsswy/p/7667491.html
Copyright © 2020-2023  润新知