407132: GYM102697 103 Home Computer
Description
You are programming your home computer. You want your computer to learn Calculus, so today you decide to write a computer program to calculate the derivative of a polynomial function.
The derivative of a "power function" $$$x^n$$$ is defined as $$$nx^{n-1}$$$. For example, the derivative of $$$x^5$$$ would be $$$5x^4$$$.
The derivative of a constant multiple of a power function $$$kx^n$$$ is defined as $$$knx^{n-1}$$$. For example, the derivative of $$$3x^4$$$ would be $$$12x^3$$$.
When taking the derivative of several terms added or subtracted to each other, you take the derivative of each term individually. For example, the derivative of $$$3x^5 - 5x^4$$$ would be $$$15x^4 - 20x^3$$$.
The "power rule" described above works intuitively if all terms have at least a degree of two (the number that $$$x$$$ is taken to the power of). For terms with a degree of one, such as $$$7x$$$, the derivative is just the constant multiple in front of $$$x$$$, which is $$$7$$$ for this example. For constant terms (with a degree of zero), the derivative is zero, and can be cancelled out.
Using this knowledge, your task is to write a program to determine the derivative of a given polynomial function.
InputThe only line of input contains a polynomial function. Each term in the polynomial function will be separated either by " + " or " - " (with a space on either side). See the example inputs to further understand the formatting. Additionally, you are guaranteed that the first term in the polynomial is not a constant.
OutputOutput a single line, consisting of a polynomial, in the format described above: the derivative of the given polynomial function.
ExamplesInput5x^5 + 3x^4 + 2x^3 + 8x^2 + 9x + 10Output
25x^4 + 12x^3 + 6x^2 + 16x + 9Input
x + 10 + 3x + 5 + 8x + 16x^7 + 8x^30 + 300x^200Output
1 + 3 + 8 + 112x^6 + 240x^29 + 60000x^199Note
If you're using Java, take in the line of input, and use the .split(" ") command to separate it by spaces, rather than using scn.nextInt() or something similar.