题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <iostream> #include "cstdio" #include "map" using namespace std;
int main() { int k; map<int, float, greater<int>> nums; cin>>k; int exp, count = 0; float coef; for (int i = 0; i < k; ++i) { cin>>exp>>coef; nums.insert({exp,coef}); } cin>>k; for (int i = 0; i < k; ++i) { cin>>exp>>coef; if (nums.find(exp) != nums.end()) { nums.find(exp)->second += coef; }else{ nums.insert({exp,coef}); } } for(auto &t: nums){ if (t.second != 0){ count++; }
} cout<<count; for(auto &t: nums){ if (t.second != 0) { printf(" %d %.1lf", t.first, t.second); } } return 0; }
|