题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream> #include <utility> using namespace std; #include<map> int main() { map<int, int> obj; int length = 0; cin >> length; for(int i =0; i< length; ++i) { int tempkey = 0; int tempvalue = 0; cin >> tempkey; cin>> tempvalue; pair temppair = make_pair(tempkey, tempvalue); if(!obj[tempkey]) { obj[tempkey] = tempvalue; } else { obj[tempkey] += tempvalue; } } for (map<int,int>::iterator it = obj.begin(); it != obj.end(); it++) { cout << it->first << " " << it->second << endl; } } // 64 位输出请用 printf("%lld")