1010. Unary polynomial derivation (25) time limit MS Memory limit 65536 KB code length limit 8000 B award Program Standard
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
Note: The input end cannot be judged by the last 0, and the output is carefully considered.
1 //1010.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <vector>7 8 using namespacestd;9 Ten class Number One { A Public: - intcoefficient;//coefficient - intPower//Index the }; - - intMain () - { +Vector<number>v; - Number num; + CharC; A at while(1) - { -CIN >> Num.coefficient >>Num.power; - - v.push_back (num); - in if((c = GetChar ()) = ='\ n')//Judgment input End - Break; to } + -Vector<number>::iterator I, end =v.end (); the * for(i = V.begin (); I! = end; i++) $ {Panax Notoginseng if(i = = V.begin () &&i->power!=0)//when not a constant and a derivative of the first element -cout << (i->coefficient) * (i->power) <<" "<< (I->power)-1; the Else if(i = = V.begin () && I->power = =0)//is a constant that only has one element +cout <<0<<" "<<0; A Else the { + if(I->power! =0) -cout <<" "<< (i->coefficient) * (i->power) <<" "<< (I->power)-1; $ } $ } - - return 0; the}
PAT B $10,101 polynomial derivative (c + + version)