+ 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

22nd Jan 2020, 4:05 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
12 Respostas
+ 9
CeePlusPlus Thx, I know ‼️☺️ As HonFu said: In 🐍 this challenge is trivial‼️☺️
23rd Jan 2020, 9:40 AM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 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? :)
22nd Jan 2020, 4:46 PM
HonFu
HonFu - avatar
+ 7
Right, Dennis, HonFu Maybe test data are poor (only */+- & never +-*/)⁉️ In other case it would be Anti-Pattern‼️
23rd Jan 2020, 9:56 AM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
21st Feb 2020, 10:18 AM
David Ashton
David Ashton - avatar
+ 6
David Ashton Thx, this challenge is really trivial in 🐍 but I've been talking about C++ & C‼️ Now it's done ‼️☺️
21st Feb 2020, 11:22 AM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 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.
22nd Jan 2020, 9:35 PM
CeePlusPlus
CeePlusPlus - avatar
+ 2
You actually don't have to deal with operator precedence in the mathematics challenge, so that's 1 thing less to worry about.
22nd Jan 2020, 6:06 PM
Dennis
Dennis - avatar
+ 2
Dennis, you need to do */ first, so isn't that one layer of operator precedence?
23rd Jan 2020, 9:42 AM
HonFu
HonFu - avatar
+ 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 +-.
23rd Jan 2020, 9:44 AM
Dennis
Dennis - avatar
+ 2
I've made it in C# and actually it could be easy with the right namespace.
17th Apr 2020, 8:10 AM
Grzegorz Dryja
Grzegorz Dryja - avatar
+ 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.
23rd Jan 2020, 12:00 PM
HonFu
HonFu - avatar
30th Aug 2020, 10:00 AM
Naveen Surya
Naveen Surya - avatar