PATA1009 Product of Polynomials

版权声明:版权归原作者CangyeChen所有,未经原作者允许不得转载本文内容,否则将视为侵权,转载或者引用本文内容请注明来源及原作者,对于不遵守此声明或者其他违法使用本文内容者,本人依法保留追究权等 https://blog.csdn.net/CANGYE0504/article/details/88827927

PATA1009 Product of Polynomials

Output Specification:
For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 3 3.6 2 6.0 1 1.6
#include<cstdio>
#include<iostream>
#define max 2001
using namespace std;
struct Poly{
	int exp;
	double cof;
} poly[1001];
double ans[2001];
 
int main()
{
	int n,m,number=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d %lf",&poly[i].exp,&poly[i].cof);
		
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		int exp;
		double cof;
		scanf("%d %lf",&exp,&cof);
		for(int j=0;j<n;j++)
		{
			ans[exp+poly[j].exp]+=(cof*poly[j].cof);
		}
	}
	for(int i=0;i<=2000;i++)
	{
		if(ans[i]!=0.0)
		{
			number++;
		 } 
		
	}
	cout<<number;
	for(int i =2000;i>=0;i--)
	{
		if(ans[i]!=0.0)
		{
			printf(" %d %.1lf",i,ans[i]); 
		}
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/CANGYE0504/article/details/88827927
今日推荐