#include<vector>
#include<iostream>
using namespace std;
const int n=1004;
int a[n],b[n],add[n],mul[n*n];
vector<int>pa,pb;
int main(){
int k;cin>>k;
while(k--){
int coe,exp;cin>>coe>>exp;
pa.push_back(exp);
a[exp]=coe;
}
cin>>k;
while(k--){
int coe,exp;cin>>coe>>exp;
pb.push_back(exp);
b[exp]=coe;
}
bool f1=true,f2=true;
for(auto x:pa)
for(auto y:pb)
mul[x+y]+=a[x]*b[y];
for(int i=n*n-1;i>=0;--i)
if(mul[i]){
if(f1)f1=false;
else cout<<' ';
cout<<mul[i]<<' '<<i;
}
if(f1)cout<<"0 0";
cout<<endl;
for(auto x:pa)add[x]+=a[x];
for(auto y:pb)add[y]+=b[y];
for(int i=n-1;i>=0;--i)
if(add[i]){
if(f2)f2=false;
else cout<<' ';
cout<<add[i]<<' '<<i;
}
if(f2)cout<<"0 0";
return 0;
}
PAT3-04. 一元多项式的乘法与加法运算
最新推荐文章于 2018-09-20 23:48:00 发布