1009 Product of Polynomials (25分)
#include <iostream>
using namespace std;
double poly1[1001];
double poly2[1001];
double multiply[2002];
int main(){
int n1, n2;
int index;
int count = 0;
cin >> n1;
for(int i=0; i<n1; i++){
cin >> index;
cin >> poly1[index];
}
cin >> n2;
for(int i=0; i<n2; i++){
cin >> index;
cin >> poly2[index];
}
for(int i=0; i<1001; i++){
if(poly1[i] != 0){
for(int j=0; j<1001; j++){
if(poly2[j] != 0){
multiply[i+j] += poly1[i] * poly2[j];
}
}
}
}
for(int i=2002; i >= 0 ; i--){
if(multiply[i] != 0)
count++;
}
cout << count;
for(int i=2002; i >= 0 ; i--){
if(multiply[i] != 0)
printf(" %d %.1lf", i, multiply[i]);
}
return 0;
}