PAT1010 一元多项式求导 (25 分)

题目

在这里插入图片描述

代码

//3 4 -5 2 6 1 -2 0
#include<iostream>
#include<vector>
using namespace std;
class Multi
{
public:
	int xishu;
	int zhishu;
};

int main()
{
	Multi temp;
	vector<Multi>arr;
	int xishu, zhishu;

	//输入
	while (cin >> xishu >> zhishu)
	{
		temp.xishu = xishu;
		temp.zhishu = zhishu;
		arr.push_back(temp);
	}

	//求导
	int i;
	int total = arr.size();
	for (i = 0; i < total; i++)
	{
		arr[i].xishu *= arr[i].zhishu;
		arr[i].zhishu -= 1;
	}

	//删除零项
	for (i = 0; i < total; i++)
	{
		if (arr[i].xishu == 0)
		{
			arr.erase(arr.begin() + i);
			i--;
			total--;
		}
	}

	//输出
	total = arr.size();
	if (total == 0)
	{
		cout << "0 0";
		return 0;
	}
	for (i = 0; i < total; i++)
	{
		cout << arr[i].xishu << ' ' << arr[i].zhishu;
		if (i != total - 1)cout << ' ';
	}

	//system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/sinat_42483341/article/details/87919824