华为OJ_1956_合并表记录

来源:互联网 发布:淘宝加盟开店被骗了 编辑:程序博客网 时间:2024/05/15 09:04
输入:  
先输入键值对的个数
然后输入成对的index和value值,以换行符隔开


输出:  
输出合并后的键值对(多行)


样例输入: 
4
3
4
0
1
0
2
1
2


                   
样例输出: 
0
3
1
2
3

4

#if 1#include <iostream>#include <map>using namespace std;int main( void ){int num;int index, value;map<int,int> mapIV;map<int,int>::iterator it;cin >> num;while( num-- ){cin >> index >> value;it = mapIV.find( index );if( it == mapIV.end() )mapIV[index] = value;elsemapIV[index] += value;}for( it = mapIV.begin(); it != mapIV.end(); ++it ){cout << it->first << endl;cout << it->second << endl;}return 0;}



0 0
原创粉丝点击