题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
好痛苦,好久不写了,手都生了 #include <iostream> #include<bits/stdc++.h> using namespace std; void print( map<int, int> mp); int main() { map<int, int> ans; int n; cin>>n; int a, b; while (cin >> a >> b) { // 注意 while 处理多个 case if(ans.find(a) == ans.end()){ //没找到,直接插入 ans[a] = b; }else{ ans[a] += b; } } print(ans); } void print( map<int, int> mp){ for(auto it : mp){ cout<<it.first<<" "<<it.second<<endl; } } // 64 位输出请用 printf("%lld")