PAT B $10,101 polynomial derivative (c + + version)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.