zoukankan      html  css  js  c++  java
  • B1010. 一元多项式求导 (25)

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

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

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

    输入样例:

    3 4 -5 2 6 1 -2 0
    

    输出样例:

    12 3 -10 1 6 0

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <string>
     6 #include <math.h>
     7 #include <algorithm>
     8 using namespace std;
     9 
    10 
    11 int main(){
    12     int a[1011]={0};
    13     int k,e,count=0;
    14     while(scanf("%d %d",&k,&e)!=EOF)
    15     {
    16         a[e]=k;
    17     }
    18     //a[0]=0;
    19     for(int i=1;i<=1010;i++)
    20     {
    21         a[i-1]=a[i]*i;
    22         //a[i]=0;
    23         if(a[i-1]!=0)count++;
    24     } 
    25     if(count==0)printf("0 0");
    26     else
    27     {
    28         for(int i=1000;i>=0;i--)
    29         {
    30             if(a[i]!=0)
    31             {
    32                 printf("%d %d",a[i],i);
    33                 count--;
    34                 if(count!=0)printf(" ");
    35             }
    36         }
    37     }
    38     
    39     return 0;
    40 }
  • 相关阅读:
    MapReduce&Yarn
    Linux网络配置问题
    Linux命令总结
    Hadoop优化&新特性
    Zookeeper
    idea中修改注释颜色
    Linuxbash未找到命令问题
    Hadoop3.0入门
    HDFS
    SpringBoot
  • 原文地址:https://www.cnblogs.com/ligen/p/4298915.html
Copyright © 2011-2022 走看看