PAT (Basic Level) Practice (中文) 1010 一元多项式求导 (25 分)

简介: PAT (Basic Level) Practice (中文) 1010 一元多项式求导 (25 分)

题目描述


设计函数求一元多项式的导数。(注:xn(n为整数)的一阶导数为n*xn-1。)


输入格式


以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。


输出格式


以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。


输入样例


3 4 -5 2 6 1 -2 0


输出样例


12 3 -10 1 6 0


分析


将数组下标作为指数次幂,数组值作为项前的系数。输入是从前往后,输出是从后往前,如果求导之后没有非零项,就直接输出两个0 0


代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a[1010]={0};
  int k,e,count=0;
  while(scanf("%d %d",&k,&e)!=EOF)
  {
    a[e]=k;
  }
  a[0]=0;
  for(int i=1;i<=1000;i++)
  {
    a[i-1]=a[i]*i;
    a[i]=0;
    if(a[i-1]!=0)
    {
      count++;
    }
  }
  if(count==0)
  {
    printf("0 0");
  }else {
    for(int i=1000;i>=0;i--)
    {
      if(a[i]!=0)
      {
        printf("%d %d",a[i],i);
        count--;
        if(count!=0)
        {
          printf(" ");
        }
      }
    }
  }
}
相关文章
|
C语言 C++
PAT (Basic Level) Practice (中文)1099 性感素数(20分)
“性感素数”是指形如 (p, p+6) 这样的一对素数。之所以叫这个名字,是因为拉丁语管“六”叫“sex”(即英语的“性感”)。(原文摘自 http://mathworld.wolfram.com/SexyPrimes.html) 现给定一个整数,请你判断其是否为一个性感素数。
109 0
|
测试技术
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
106 0
PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)+易错测试点
|
人工智能 测试技术
PAT (Basic Level) Practice (中文) B1008 数组元素循环右移问题 (20 分)
PAT (Basic Level) Practice (中文) B1008 数组元素循环右移问题 (20 分)
79 0
PAT (Basic Level) Practice (中文) B1008 数组元素循环右移问题 (20 分)
|
存储 测试技术
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
PAT (Basic Level) Practice (中文) 1004 成绩排名 (20 分)
69 0
|
算法
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
PAT (Basic Level) Practice (中文)1028. 人口普查(20分)
85 0
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
PAT (Basic Level) Practice (中文) B1046 划拳 (15 分)
65 0
|
C语言
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
PAT (Basic Level) Practice (中文) B1026 程序运行时间 (15 分)
100 0
|
编译器
PAT (Basic Level) Practice (中文)- 1077 互评成绩计算(20 分)
PAT (Basic Level) Practice (中文)- 1077 互评成绩计算(20 分)
87 0
PAT (Basic Level) Practice (中文)- 1034 有理数四则运算(20 分)
PAT (Basic Level) Practice (中文)- 1034 有理数四则运算(20 分)
84 0
PAT (Basic Level) Practice (中文)- 1051 复数乘法(15 分)
PAT (Basic Level) Practice (中文)- 1051 复数乘法(15 分)
89 0