题目描述
用double数组n来记录每一位上的数值,模拟一下就好了
C++ 代码
#include <iostream>
using namespace std;
const int N = 1010;
double n[N];
int main()
{
for (int i = 0; i < 2; i ++)
{
int k;
cin >> k;
for (int j = 0; j < k; j ++)
{
int a;
double b;
cin >> a >> b;
n[a] += b;
}
}
int k = 0;
for (int i = 0; i < N; i ++)
if (n[i] != 0) k ++;
cout << k << " ";
for (int i = N - 1; i >= 0; i --)
if (n[i] != 0) printf("%d %.1lf ", i, n[i]);
}
谢谢你