+ 18
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
12 Respostas
+ 9
very interesting and hard challenge đ
+ 6
@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 đđ
+ 6
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
+ 6
Anyone have any luck with this?
+ 6
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
+ 5
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
+ 2
more operations and brackets would be added to the task.
+ 1
https://code.sololearn.com/cOCaq45bP2HK/#py
i hope, this ans is correct
+ 1
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
0
Hi! System convert this expression into postfix expression after that solve it