Order of operations [Challange]
Using only addition,subtraction and multiplication perform the following. User input> 5 - 2 * 2 + 4 * 5 System outputs > step1> 2 * 2 = 4 step2> 4 * 5 = 20 step3> 5 - 4 = 1 step4> 1 + 20 = 21 Challange by D_Stark
1/26/2018 5:05:24 PM
D_Stark
12 Answers
New Answer@Vukan i havent tried it yet 😄 but i was trying to think up a challange for my self to use format(), binary, bitwise and regex so i come up with this but i might not need all that 😜 i think if i can see whats on either side of the operator it shouldent be too bad.... says me lol 😀😀
use the concept of stack first convert the give expression into postfix or prefix expression and then apply the evaluation of postfix or prefix expression
here's my code again, bugs fixed and, ui changed, please report any bugs. thanks for the challenge, gave me a good RegEx exercise. https://code.sololearn.com/WE8xzWCz5553/?ref=app
Nice try @Gordie But try to do some changes and correct ur code. As mentioned in comment is not working properly for input : 12 + 3 * 2 / 6
Hello all and Michail Getmanskiy, D_Stark , I have attached my code here please check it out. Some notes related to my code. 1. It will work for basic operations like +, -, *, / and %. It also processes parenthesis. 2. I have used the concept like expression tree. But I haven't used any data structures to find out the steps. It's pure logic used to find the next step. Sample test case which is given : Input : 5 -2 * 2 + 4 * 5 Output : Step 1 : 2 * 2 = 4 Step 2 : 5 - 4 = 1 Step 3 : 4 * 5 = 20 Step 4 : 1 + 20 = 21 Final result : 21 Explanation: Steps Remaining Exp. 1: 2 * 2 = 4 5 - 4 + 4 * 5 2: 5 - 4 = 1 1 + 4 * 5 3: 4 * 5 = 20 1 + 20 4: 1 + 20 = 21 21 In solution version v2 I will try to get the ans like given in question. https://code.sololearn.com/cFI79zCiU4dL/?ref=app