← Back to problems

35. Inventory Tracker

EASY
EasyHASH MAPLLDState

Track stock levels per item, rejecting removals that exceed the quantity on hand.

Track quantities of named items. Every item starts at zero stock. Process commands from stdin, one per line. Commands: - ADD <item> <qty> : increase the item's stock by qty. Print "OK <newStock>". - REMOVE <item> <qty> : if the item has at least qty in stock, decrease it and print "OK <newStock>". Otherwise reject (stock unchanged) and print "DENIED <currentStock>". - QUERY <item> : print the item's current stock (0 if never added). All quantities are positive integers.
Log in to submit a solution

Comments

Log into join the discussion.