当前位置:网站首页>Hj8 consolidated statement record
Hj8 consolidated statement record
2022-07-27 15:39:00 【coder_ Alger】
describe
Data table records contain table indexes and values (int The positive integer of the range ), Please merge records with the same table index , That is to sum the values of the same index , Output according to key Values in ascending order are output .
Input description :
First enter the number of key value pairs
Then type in pairs of index and value value , Space off
Output description :
Output the merged key value pairs ( Multiple lines )
Example 1
Input :
4 0 1 0 2 1 2 3 4
Output :
0 3 1 2 3 4
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n;
map<int,int>m;
cin>>n;// Enter the number of key value pairs
for(int i = 0;i<n;i++)
{
pair<int,int>tmp;
cin>>tmp.first;
cin>>tmp.second;
if(m.find(tmp.first)!= m.end())
{
//m[tmp.first] += tmp.second
m[tmp.first] += tmp.second;
}
else
{
m[tmp.first] = tmp.second;
}
}
for(map<int,int>::iterator it = m.begin();it != m.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}
边栏推荐
- Leetcode 81. search rotation sort array II binary /medium
- Network equipment hard core technology insider router Chapter 13 from deer by device to router (Part 1)
- Adaptation verification new occupation is coming! Huayun data participated in the preparation of the national vocational skill standard for information system adaptation verifiers
- Spark RPC
- Using Prometheus to monitor spark tasks
- Binder初始化过程
- C语言:自定义类型
- QT (XIII) qchart drawing line chart
- 【剑指offer】面试题50:第一个只出现一次的字符——哈希表查找
- Network equipment hard core technology insider router Chapter 11 Cisco asr9900 disassembly (V)
猜你喜欢

/dev/loop1占用100%问题

Tools - common methods of markdown editor

【剑指offer】面试题42:连续子数组的最大和——附0x80000000与INT_MIN

Leetcode 781. rabbit hash table in forest / mathematical problem medium

Complexity analysis

使用Lombok导致打印的tostring中缺少父类的属性

C语言:自定义类型

MySQL interview 40 consecutive questions, interviewer, if you continue to ask, I will turn my face

Troubleshooting the slow startup of spark local programs

HaoChen CAD building 2022 software installation package download and installation tutorial
随机推荐
Cap theory and base theory
How to edit a framework resource file separately
multimap案例
js使用for in和for of来简化普通for循环
Spark Filter算子在Parquet文件上的下推
初识结构体
C语言:动态内存函数
Network equipment hard core technology insider router Chapter 18 dpdk and its prequel (III)
Binder初始化过程
Two stage submission and three stage submission
Spark 3.0 DPP实现逻辑
Leetcode 190. reverse binary bit operation /easy
【剑指offer】面试题52:两个链表的第一个公共节点——栈、哈希表、双指针
Network equipment hard core technology insider router Chapter 9 Cisco asr9900 disassembly (II)
Huayun data creates a perfect information technology and innovation talent training system to help the high-quality development of information technology and innovation industry
C语言中交换两数的方法
Spark RPC
数组名是首元素地址吗?
QT (five) meta object properties
TCC