The design function is to find the derivative of the polynomial of one element. (Note: The first-order derivative of xn (n is an integer) is n*xn-1. )
input format: input polynomial non-0 coefficients and exponents in exponential degradation (absolute values are integers not exceeding 1000). The numbers are separated by a space.
output format: outputs the coefficients and exponents of the derivative polynomial not 0 in the same format as the input. The numbers are separated by a space, but cannot have extra spaces at the end. Note that the exponent and coefficients for the "0 polynomial" are 0, but are expressed as "0 0".
Input Sample:
3 4-5 2 6 1-2 0
Sample output:
12 3-10 1) 6 0
#include <iostream>#include<string>using namespaceStd;typedefstructlnode{intCoe; intindex; structLnode *Next;} Pol;intMain () {intcoe,index,n=0; Pol*head=NewPol; Pol*p=Newpol,*Q; Head->next=p; while(cin>>coe>>index) {P->coe=Coe; P->index=index; N++; Q=p; P=NewPol; Q->next=Q; } q->next=NULL; Deletep; P=head->Next; while(p!=NULL) {P->coe=p->coe*p->index; if(p->index!=0) P->index=p->index-1; P=p->Next; } P=head->Next; while(p!=NULL) { if(P->next!=null && p->index==0&& p->next->index==0) {Q=p->Next; P->next=q->Next; DeleteQ; } if(P->next!=null && p->next->coe==0) {Q=p->Next; P->next=q->Next; DeleteQ; } P=p->Next; } P=head->Next; while(p!=NULL) {cout<<p->coe<<" "<<p->index; if(p->next!=NULL) {cout<<" "; } P=p->Next; } return 0;}
after 19 commits, it was finally successful. It's important to read a question.
Data structure Exercise 02-linear structure 1. Derivation of one-dimensional polynomial (25)