Given a mathematical equation using numbers/variables and +, -, *, /. Print the equation in reverse.
Input : 20 - 3 + 5 * 2 Output : 2 * 5 + 3 - 20 Input : 25 + 3 - 2 * 11 Output : 11 * 2 - 3 + 25 Input : a + b * c - d / e Output : e / d - c * b + a
Approach : The approach to this problem is simple. We iterate the string from left to right and as soon we strike a symbol we insert the number and the symbol in the beginning of the resultant string.
This article is contributed by Raghav Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the missing value from the given equation a + b = c
- Validation of Equation Given as String
- Check if string can be made lexicographically smaller by reversing any substring
- Count of all unique substrings with non-repeating characters
- Minimum splits required to convert a number into prime segments
- Largest and Smallest N-digit Octal Numbers
- Sort an Array of Strings according to the number of Vowels in them
- Sort an array of Strings according frequency
- Count of substrings whose Decimal equivalent is greater than or equal to K
- Perfect Cube String
- Program to find the XOR of ASCII values of characters in a string
- Strings formed from given characters without any consecutive repeating characters
- Count of sticks required to represent the given string
- Count of sub-strings with equal consecutive 0's and 1's
Improved By : Akanksha_Rai