Topic:
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
Analysis: The main test is to store the linear structure through the chain list, pay attention to the input termination judgment and the linked list insert operation
C language (null was replaced with NULL when the commit was made 0)
typedefstructnode{intCoe//coefficient intExp//Index structNode *next;//next item} list;typedefstructHead {structNode *begin; structNode *end;} Nodehead; List*insert (intCoeintExp, Nodehead *Ptrl);intMain () {Nodehead*head = (Nodehead *)malloc(sizeof(Nodehead)); Head->begin =0; Head->end =0; intTempcoe, Tempexp; while(SCANF ("%d%d", &tempcoe, &tempexp)! =0{Insert (Tempcoe, Tempexp, head); if(GetChar () = ='\ n') { Break; }} List*ptr = head->begin; if(PTR) {if(Ptr->coe * Ptr->exp = =0) {printf ("0 0"); } Else{printf ("%d%d", Ptr->coe * ptr->exp, Ptr->exp-1); } ptr= ptr->Next; while(PTR) {if(Ptr->coe * Ptr->exp = =0) { //printf ("0 0");}Else{printf ("%d%d", Ptr->coe * ptr->exp, Ptr->exp-1); } ptr= ptr->Next; }}}list*insert (intCoeintExp, Nodehead *head) {List*l = (List *)malloc(sizeof(List)); if(! (head->begin)) {Head->begin =l; } List*end = head->end; if(end) {End->next =l; } head->end =l; L->coe =Coe; L->exp =exp; returnl;}
Operation result :
PAT001 the derivation of one-element polynomial