输入:
先输入键值对的个数
然后输入成对的index和value值,以换行符隔开
输出:
输出合并后的键值对(多行)
样例输入:
4
3
4
0
1
0
2
1
2
样例输出:
0
3
1
2
3
先输入键值对的个数
然后输入成对的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;
else
mapIV[index] += value;
}
for( it = mapIV.begin(); it != mapIV.end(); ++it ){
cout << it->first << endl;
cout << it->second << endl;
}
return 0;
}