_CodeBehind

HackerRank

Jun 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. If you receive a product, which already exists in the database, increase its quantity by the input quantity and if its price is different, replace the price as well.
  2. You will receive products’ names, prices and quantities on new lines. Until you receive the command “stocked”, keep adding items to the database. When you do receive the command “stocked”, print the items with their names, prices, quantities and total price of all the products with that name. When you’re done printing the items, print the grand total price of all the items.
  3. Note: The grand total is calculated, based on the latest price of the products.
  4. Constraints:
  5. -Until you receive “stocked”, the products come in the format: “{name} {price} {quantity}”.
  6. -The product data is always delimited by a single space.
  7. Output
  8. -Print information about each product, following the format:
  9. "{name}: ${price:F2} * {quantity} = ${total:F2}"
  10. -On the next line, print 30 dashes.
  11. -On the final line, print the grand total in the following format:
  12. “Grand Total: ${grandTotal:F2}”
  13.  
  14. Examples:
  15. input:
  16. Beer 2.40 350
  17. Water 1.25 200
  18. IceTea 5.20 100
  19. Beer 1.20 200
  20. IceTea 0.50 120
  21. stocked
  22.  
  23.  
  24. output:
  25. Beer: $1.20 * 550 = $660.00
  26. Water: $1.25 * 200 = $250.00
  27. IceTea: $0.50 * 220 = $110.00
  28. ------------------------------
  29. Grand Total: $1020.00
Add Comment
Please, Sign In to add comment