【PTA-B】1010 一元多项式求导 (25 分)

 

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805313708867584

 定义ab数组,a数组为原始输入。k为系数,n为指数,a[n]=k。b存储求导后的数组b[i]=a[i+1]*(i+1)。其中b[0]一定为0。用count记录指数在1以上的次数,如果count等于0,就输出0 0。

注意点:

1.指数为0的项导数一定为0,不用计数

2.末尾不需要空格

3.当求导后除0外没有其他指数项时,输出0 0。

#include<iostream>
using namespace std;
int main() {
	int a[1001] = {0}, b[1001] = { 0 };
	int k,n,count=0;
	while (cin>>k>>n) {
		a[n] = k;
	}
	for (int i = 0; i < 1000; i++) {
		if (a[i + 1] != 0) {
			b[i] = a[i + 1] * (i + 1);
			count++;
		}
	}
	if (count == 0) { cout <<"0 0"; }
	else {
		for (int i = 1000; i >= 0; i--) {
			if (b[i] != 0) {
				cout << b[i] << " " << i;
				count--;
				if (count != 0)cout << " ";
			}
			
		}
	}
	return 0;
}

 

posted @ 2019-09-24 14:57  大帅本帅  阅读(9)  评论(0)    收藏  举报