`
风吹过PP好冷
  • 浏览: 36636 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

PAT1009 Product of Polynomials

    博客分类:
  • PAT
 
阅读更多

多项式乘法

 

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 <string.h>
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{    
	int K1,K2;
	int count = 0;
	float V1[1001] = {0};
	float V2[1001] = {0};
	float V3[2002] = {0};
	map<int, float> MapX;
	cin>>K1;
	while(K1--)
	{
		int i;
		float x;
		cin>>i>>x;
		V1[i] = x;
	}
	cin>>K2;
	while(K2--)
	{
		int i;
		float x;
		cin>>i>>x;
		V2[i] = x;
	}

	for (int i = 0; i < 1001; i++)
	{
		for (int j = 0; j < 1001; j++)
		{
			V3[i+j] = V1[i]*V2[j] + V3[i+j];
		}        
	}

	for (int i = 2001; i >=0; i--)
	{
		if (V3[i] != 0)
		{
			count++;
		}
	}
	cout<<count;

	for (int i = 2001; i >=0; i--)
	{
		if (V3[i] != 0)
		{
			cout.setf(ios::fixed);
			cout<<" "<<i<<" "<<setprecision(1)<<V3[i];
		}
	}

	return 0;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics