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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if string can be made lexicographically smaller by reversing any substring
- String obtained by reversing and complementing a Binary string K times
- Find the missing value from the given equation a + b = c
- Validation of Equation Given as String
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Perform range sum queries on string as per given condition
- Generate a String of having N*N distinct non-palindromic Substrings
- Lexicographically largest possible String after removal of K characters
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Check if a given string is Pangram in Java
- C program to trim leading white spaces from String
- Generate all possible permutations of a Number divisible by N
- Construct an Array of Strings having Longest Common Prefix specified by the given Array
- Count of Distinct Substrings occurring consecutively in a given String