zoukankan      html  css  js  c++  java
  • Programming Ability Test学习 02-线性结构2. 一元多项式求导 (25)

    02-线性结构2. 一元多项式求导 (25)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard

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

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

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

    输入样例:
    3 4 -5 2 6 1 -2 0
    
    输出样例:
    12 3 -10 1 6 0
    
    #include<stdio.h>
    #include<stdlib.h>
    #include <malloc.h>
    typedef struct Node
    {
       int dex;
       int cof;
       struct Node * Next;
    }node;
    
    
    int main()
    {
        //Qlink newLink;
        //newLink=(Link*)malloc(sizeof(Link));
        struct Node *head,*tail;
        head=(node*)malloc(sizeof(node));
        tail=(node*)malloc(sizeof(node));
        tail->Next=NULL;
        head->Next=tail;
    
        struct Node *pthis,*pthat;
        pthis=head;pthat=pthis;
        //输入参数
        int dex,cof;
        
        while(scanf("%d %d",&dex,&cof)){
        pthis=(node*)malloc(sizeof(node));
        pthis->dex=dex;pthis->cof=cof;
        pthis->Next=pthat->Next;
        pthat->Next=pthis;
        pthat=pthis;
        if(getchar()=='
    ')break;
        }
        
        //遍历 
        pthat=head->Next;
        if(pthat->Next->Next==NULL&&pthat->cof==0)
        {
            printf("0 0
    ");
        }
        else{
        while(pthat!=NULL&&pthat->Next!=NULL)
        {
            pthat->dex=pthat->dex*pthat->cof;
            pthat->cof-=1;
            if(pthat->dex!=0){ 
            printf("%d %d",pthat->dex,pthat->cof);
            if(pthat->Next->Next!=NULL&&pthat->Next->dex*pthat->Next->cof!=0)printf(" ");
            else printf("
    "); 
            } 
            pthat=pthat->Next;
        }
        }
        //free(pthat);
        free(pthis);free(head);free(tail);
        return 0;
    
    } 
  • 相关阅读:
    C# 动态加载控件 (转)
    SQL 周月时间段
    js调用xml数据显示div层上下滚动的公告
    使用半透明的DIV实现禁用页面功能(转)
    学习jQuery第一天"Hello!How are you!"
    HTML生成类
    从无限畅想转来的
    SQL递归查询子类型
    js 图片缩显
    2020年统计用区划代码和城乡划分代码:安徽省乡镇编码
  • 原文地址:https://www.cnblogs.com/a842297171/p/4744297.html
Copyright © 2011-2022 走看看