Given a polynomial string str, the task is to integrate the given string and print the string after integrating it.
Note: The input format is such that there is a whitespace between a term and the ‘+’ symbol.
Input: str = “4X3 + 3X1 + 2X2”
Output: X4 + (3/2)X2 + (2/3)X3 + C
Input: str = “5X3 + 7X1 + 2X2 + 1X0”
Output: (5/4)X4 + (7/2)X2 + (2/3)X3 + Xq + C
Approach: The idea is to observe that when the given equation consists of multiple polynomials , the integration of the given polynomial .
Also it is known that the indefinite integral of is .
Therefore, we split the given string and integrate every term in it.
Below is the implementation of the above approach:
(5/4)X^4 + (7/2)X^2 + (2/3)X^3 + (1/1)X^1 + C
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.