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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- String obtained by reversing and complementing a Binary string K times
- Longest substring that starts with X and ends with Y
- Print all possible palindromic string formed using any pair of given strings
- Check if a string can be split into two strings with same number of K-frequent characters
- Count of substrings having all distinct characters
- Calculate weight of parenthesis based on the given conditions
- Smallest number greater than X which is K-periodic
- Check if a given string is a Reverse Bitonic String or not
- Check if a given string is Even-Odd Palindrome or not
- Maximum time such that absolute difference between hour and minute lies in given range
- How to check if string contains only digits in Java