题解 | 合并表记录
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <iostream> #include <map> using namespace std; int main() { int n; cin >>n; map<int,int> m; while(n--){ pair<int,int>i; cin >> i.first >>i.second; m[i.first] += i.second; } for(auto i : m){ cout << i.first << ' '<< i.second <<endl; } } // 64 位输出请用 printf("%lld")
这个题非常细节。特别是这个头文件使用,此外,为什么不使用unordered_map,不使用map这个头文件都值得思考一下,