405152: GYM101807 D Differentiation

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Differentiationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Write a program to differentiate a polynomial in x.

Here's how to differentiate a polynomial in the form

$$$c_nx^n+c_{n-1}x^{n-1}+\cdots+c_1x+c_0$$$

Each term $$$c_ix^i$$$ where $$$i \ge 1$$$ can be handled individually:

  1. Multiply the coefficient $$$c_i$$$ by $$$i$$$.
  2. Decrease the exponent of $$$x$$$ by 1.
  3. Therefore, the result of the term is $$$(c_i\times i)x^{i-1}$$$

Finally, join the results of the terms together to form the final polynomial. Also, the derivative of the constant term is 0.

For example, the derivative of $$$-3x^3+5x^2-7x+4$$$ is $$$(-3\times 3)x^{3-1}+(5\times 2)x^{2-1}+(7\times 1)x^{1-1}+0$$$ = $$$-9x^2+10x-7$$$

The polynomial's format is similar to the requirements for math homework:

  • The polynomial does not start with a plus sign.
  • The polynomial contains no spaces.
  • The terms should be ordered in strictly decreasing degree of $$$x$$$.
  • There should be no redundant terms. The term is omitted if the coefficient is 0.
  • The 1 is omitted if the coefficient is 1 or -1. (see sample 1)
  • The degree is written directly after x. The exponent is omitted if the degree is 1.
  • The constant term is omitted if it is zero, except that when the whole polynomial is zero (see sample 3).
Therefore, there is only one way to format a polynomial correctly.Input

The input consists of a string: the polynomial. The maximum degree of $$$x$$$ is 99 and the coefficients are integers between -99 and 99, including -99 and 99 but excluding 0. The length of the string is at most 100.

It's guaranteed that the string strictly follows the format, i.e. +0x1-1x2+0 is not a possible input.

Output

Output the derivative of the polynomial. It must strictly follow the format.

ExamplesInput
4x5-x2
Output
20x4-2x
Input
-6x+3
Output
-6
Input
5
Output
0
Input
-3x3+5x2-7x+4
Output
-9x2+10x-7

加入题单

上一题 下一题 算法标签: