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 firstname.lastname@example.org. 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
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Longest palindromic String formed using concatenation of given strings in any order
- Count of lexicographically smaller characters on right
- Program to build a DFA to accept strings that start and end with same character
- Program to build a DFA that accepts strings starting and ending with different character
- Program to print the given digit in words
- Sum of all LCP of maximum length by selecting any two Strings at a time
- Print all possible combinations of words from Dictionary using Trie
- Find minimum number of steps to reach the end of String
- Program to build a DFA that checks if a string ends with "01" or "10"
- Reverse all the word in a String represented as a Linked List
Improved By : Akanksha_Rai