Hello v7n Users,
This is my First Thread in this forum.
So welcome all,
I want to share with you a great task for programmers that everyone should know at least its solution
Well, here is the Problem:
When I travel over the city by public transport, I get the ticket which usually contains 6-digit number and start trying to build an arithmetic expression from this number according to following rules:
between any two digits one of the operators +, -, *, / could be inserted – or these digits could be just "glued" together to form a larger value;
brackets could be added to provide correct operations priority;
the expression should yield 100 as a result.
For example, yesterday it was number 151374 which could be solved in several ways:
1 + (5 + 1 + 3) * (7 + 4) = 100
(1 * 5) + (13 * 7) + 4 = 100
If ever I could not come up with solution I wonder, whether it is really not possible or I am just not smart enough. So let us write the program to help checking this out. We will try to solve this for different target values, not necessarily for 100.
Few restrictions: – let us agree that division could be used only if the first value is divisible by the second; – please surround every binary operation by brackets to avoid priority issues (and help checking your expression) – i.e. expression with 5 operators should have 5 opening and 5 closing brackets; – unary minus operation is not allowed, though intermediate results inside expression could be negative.
Input data will contain amount of test cases in the first line.
Next lines will contain test cases – the ticket number and the "target" value (separated by equals sign).
Answer should contain proposed expression for each test case. If there is no solution – output zero. Separate answers with spaces (but do not use spaces inside expression).
answer: (1+((5+1)+3)*(7+4)) (256-128) ((((5*7)*7)-97)+6) 0 (((7-6)*74)+94)
Can you solve this?
Well, You can also check the solutions:
Java solution for you:yamechanic.com/9fk6
C++ Solution: yamechanic.com/9flV
PHP Solution: yamechanic.com/9fms
and Python Solution: yamechanic.com/9foU
Leave reviews or question it you want me to explain more..
Thanks for reading this thread!
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!