Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will this work?
#1
IT'S A TRAP!

Write a function "void noparens(char *expression)" that prints all the possible different results you can get from different grouping of parentheses in the given expression.

The string 'expression' contains the operators '+', '-', '*' and positive integers (or possibly no operators and just one integer). The expression is entirely unparenthesized. Your function should determine the result of every possible parenthesization of the expression and print the distinct ones.

Don't worry about overflowing int or strange formatting of the expression.

Examples:
A. expression "1 + 2 - 3 * 4"
(((1 + 2) - 3) * 4) = 0
((1 + 2) - (3 * 4)) = -9
((1 + (2 - 3)) * 4) = 0
(1 + ((2 - 3) * 4)) = -3
(1 + (2 - (3 * 4))) = -9
There were five possible, but two were the same, so your function should print:
3 unique { 0, -9, -3 }

B. expression "1 - 1 + 1"
((1 - 1) + 1) = 1
(1 - (1 + 1)) = -1
Your function should print:
2 unique { 1, -1 }

C. expression "10"
1 unique { 10 }

D. expression "1 + 2 + 3 * 4 - 5 * 2"
18 unique { 38, 14, -12, -36, 20, 5, 17, 0, -3, -15, 32, 11, 31, -8, -9, -29, 19, -1 }
Reply

#2
What?
Reply

#3
(10-05-2011, 17:39)Lemon Wrote: What?

Read it all over again

Reply

#4
my brain hurts
Reply

#5
1+1 = 2
Reply

#6
2+2*2 = 6
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#7
this isnt a school assignment. type so people can actually understand it
YouTube 1:Azumikkel- Modding
YouTube 2:DerpShark- Gaming Entertainment
Website:Jensby.me
Contact: im[at]jensby.me
Reply

#8
(10-05-2011, 18:09)Se7en Wrote: 2+2*2 = 6

Too mainstream.
Reply

#9
...what

Huh
[Image: lQDUjba.jpg]
Reply

#10
2 lemons + 3 oranges = OMA
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Help Permissions DOESNT work Hallla 2 3,069 08-18-2013, 11:28
Last Post: hillbilly
  why permissions dont work. ? ExoGamer* 4 3,313 07-21-2013, 13:46
Last Post: X-Track
  Bunker Plugin Won't work OBJAY 4 4,519 06-03-2013, 15:48
Last Post: X-Track
  Help prefix doesnt work with shop koro35 2 2,904 05-18-2013, 10:51
Last Post: koro35
  Help Perks do not work (( x1412 6 4,425 04-06-2013, 18:09
Last Post: x1412
  liberation dont work? puistis 7 7,823 02-18-2013, 09:17
Last Post: JariZ
  Weapon dont work?? Erik The Born 3 2,875 02-05-2013, 19:53
Last Post: Yamato
  private match maps won't work with mods! leereef 1 2,519 01-13-2013, 12:01
Last Post: surtek
  Some images do not work with SetShader xplosiff 8 5,141 01-05-2013, 07:19
Last Post: mw2killer
  Help !giveammo Plugin doesnt work [solved] Hallla 3 3,581 12-29-2012, 20:53
Last Post: Hallla

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.