#include "iostream"
#include "map"
#include "set"
#include "vector"
using namespace std;
map<int, double> res;
set<int> set_ex;
int k, ex;
double co;
int main()
{
cin >> k;
while (k-- > 0)
{
cin >> ex >> co;
if (res.find(ex) != res.end())
res[ex] += co;
else
res[ex] = co;
if (set_ex.find(ex) == set_ex.end())
set_ex.insert(ex);
}
cin >> k;
while (k-- > 0)
{
cin >> ex >> co;
if (res.find(ex) != res.end())
res[ex] += co;
else
res[ex] = co;
if (set_ex.find(ex) == set_ex.end() && res[ex] != 0)
set_ex.insert(ex);
if(set_ex.find(ex)!=set_ex.end()&&res[ex]==0)
set_ex.erase(set_ex.find(ex));
}
cout << set_ex.size();
if (set_ex.size() == 0)
return 0;
for (auto it = set_ex.rbegin(); it != set_ex.rend(); it++)
{
cout << " ";
printf("%d", *it);
cout << " ";
printf("%.1lf", res[*it]);
}
return 0;
}
//#1 2 1 1.0 2 1.0 2 1 1.0 2 1.0
//#2 0 0
//#3 10
//#4 2 1 2.4 0 3.2 2 2 1.5 1 0.5
//#5 2 1.1 2.4 0.1 3.2 2 1.1 1.5 2.1 1.5
//#6 1 1 1.0 1 1 -1.0当系数为0时不算一项
//这一题主要是当系数为0时它不算一项了
//我是菜鸡
PAT1002
最新推荐文章于 2024-05-31 00:26:19 发布