+ 15
Mathematics - Code Coach Challenge‼️ How to consider the fact that an expression can include multiple operations⁉️🤔
My code in C++ & C, fails test 4 & 5 probably because it accepts only one operation in an expression⁉️🤔 I don't want to parse deeper in expression string because of the operators precedence‼️There must be an easier way‼️😃 I don't feel comfortable in C++ & C so help needed⁉️🤔 https://code.sololearn.com/cGy4FlymNnKe/?ref=app
12 Antworten
+ 9
CeePlusPlus Thx, I know ‼️☺️
As HonFu said: In 🐍 this challenge is trivial‼️☺️
+ 7
Actually, yeah, they want you to do longer expressions, handling operators precedence.
In Python of course it is trivial, but in C, for me it was quite a fight to get it right.
I also think it is one of the few rewarding tasks of Code Coach, so... you sure you don't want to rack your brain about it a while longer? :)
+ 6
A trivial answer 😄
https://code.sololearn.com/cZa6PhU2BOQg
+ 6
David Ashton Thx, this challenge is really trivial in 🐍 but I've been talking about C++ & C‼️ Now it's done ‼️☺️
+ 3
In python, there is a function named eval that actually solves equations, that are in string form. That's how I solved the code coach.
+ 2
You actually don't have to deal with operator precedence in the mathematics challenge, so that's 1 thing less to worry about.
+ 2
Dennis, you need to do */ first, so isn't that one layer of operator precedence?
+ 2
HonFu I parsed the expressions in order and did not take operator precedence into account and it passed all tests.
I'm guessing there is no */ after a +-.
+ 2
I've made it in C# and actually it could be easy with the right namespace.
+ 1
Ah, okay, so another sloppy set of tests... 🙄
What a pity, otherwise it would be a rather good one, preparing you for more complicated parsing.