注意最后遍历不要包含maxn
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 10;
double a[maxn], b[maxn], c[maxn];
int k;
void read(double a[])
{
scanf("%d", &k);
for (int i = 0; i < k; i++)
{
int exp;
double coef;
scanf("%d%lf", &exp, &coef);
a[exp] = coef;
}
}
int main()
{
read(a);
read(b);
for (int i = 0; i < maxn; i++)
{
if (a[i])
{
for (int j = 0; j < maxn; j++)
{
if (b[j])
{
c[i + j] += a[i] * b[j];
}
}
}
}
int cnt = 0;
for (int i = 0; i < maxn; i++)
{
if (c[i])cnt++;
}
printf("%d", cnt);
for (int i = maxn-1; i >= 0; i--)
{
if (c[i])printf(" %d %.1f", i, c[i]);
}
return 0;
}