PAT (Advanced Level) 1009. Product of Polynomials (25)

简单模拟。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std; double a[],b[],c[];
int k; int main()
{
for(int i=;i<=;i++) a[i]=b[i]=c[i]=;
int Max=-;
scanf("%d",&k);
for(int i=;i<=k;i++)
{
int id;double num;
scanf("%d%lf",&id,&num);
a[id]=num;
} scanf("%d",&k);
for(int i=;i<=k;i++)
{
int id;double num;
scanf("%d%lf",&id,&num);
b[id]=num;
} for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
c[i+j]+=a[i]*b[j];
}
} int cnt=;
for(int i=;i>=;i--)
if(c[i]!=) cnt++; printf("%d",cnt);
int op=;
for(int i=;i>=;i--)
if(c[i]!=)
printf(" %d %.1lf",i,c[i]);
return ;
}
上一篇:转:基于IOS上MDM技术相关资料整理及汇总


下一篇:[LeetCode] 123. Best Time to Buy and Sell Stock III 买卖股票的最佳时间 III