Advertisement
vladimirVenkov

Online Market Task

Jul 30th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.89 KB | None | 0 0
  1. You are given an online market. Products can be added and queried in the market. You are given a sequence of commands that must be implemented:
  2.  
  3. Commands
  4. add PRODUCT_NAME PRODUCT_PRICE PRODUCT_TYPE – adds a new product to the market
  5. PRODUCT_NAME can be any unique sequence of 3 to 20 characters
  6. PRODUCT_PRICE can be any positive floating-point number, up to 5000
  7. PRODUCT_TYPE can be any sequence of 3 to 20 characters. Product type may not be unique
  8. Print "Ok: Product PRODUCT_NAME added successfully" if the product is added
  9. Print "Error: Product PRODUCT_NAME already exists" if the product already exists
  10. filter by type PRODUCT_TYPE – lists the first 10 products that have the given PRODUCT_TYPE
  11. Print "Error: Type PRODUCT_TYPE does not exists", if the given PRODUCT_TYPE is non-existent
  12. filter by price from MIN_PRICE to MAX_PRICE – lists the first 10 products that have PRODUCT_PRICE in the given range, inclusive
  13. filter by price from MIN_PRICE – lists the first 10 products that have a greater PRODUCT_PRICE than the given, inclusive
  14. filter by price to MAX_PRICE – lists the first 10 products that have a smaller PRODUCT_PRICE that the given, inclusive
  15. end – marks the end of the commands. No commands will follow
  16. Info about the commands
  17. All products that are listed by the filter commands must be printed in the format "Ok: LIST_OF_PRODUCTS".
  18.  
  19. LIST_OF_PRODUCTS contains the filtered products, separated by a space and a comma (", ") and each product is represented as "PRODUCT_NAME(PRODUCT_PRICE)".
  20.  
  21. If the result from the filtering by price is 0 products, then print "Ok: ".
  22. They must also be sorted by the following criteria:
  23. First by PRODUCT_PRICE, ascending
  24. Then by PRODUCT_NAME, ascending
  25. Last by PRODUCT_TYPE, ascending
  26. Input
  27. The input data is given at the standard input. It consists of a sequence of commands, each at a separate line, ending by the command "end". The commands will be valid (as described in the above list), in the specified format, within the constraints given below. There is no need to check the input data explicitly.
  28.  
  29. Output
  30. For each command from the input sequence print at the standard output its result as a single line.
  31.  
  32. Constraints
  33. All PRODUCT_NAME and PRODUCT_TYPE will consist of letters and digits only. No spaces are allowed.
  34. All filter by price * commands will occur no more than 100 times in any test, and approximately 2% of all commands in a test
  35. The total number of lines in the input will be in the range [150 000]
  36. Sample Tests
  37. Input
  38. Copy
  39. add Milk 1.90 dairy
  40. add Yogurt 1.90 dairy
  41. add Notebook 1111.90 technology
  42. add Orbit 0.90 food
  43. add Rakia 11.90 drinks
  44. add Dress 121.90 clothes
  45. add Jacket 49.90 clothes
  46. add Milk 1.90 dairy
  47. add Eggs 2.34 food
  48. add Cheese 5.55 dairy
  49. filter by type clothes
  50. filter by price from 1.00 to 2.00
  51. add CappyOrange 1.99 juice
  52. add Nestey 2.7 juice
  53. filter by price from 1200
  54. add Socks 2.90 clothes
  55. filter by type fruits
  56. add MacBookPro 1700.1234 technology
  57. filter by price from 1200
  58. filter by price from 1.50
  59. filter by price to 2.00
  60. filter by type clothes
  61. end
  62. Output
  63. Copy
  64. Ok: Product Milk added successfully
  65. Ok: Product Yogurt added successfully
  66. Ok: Product Notebook added successfully
  67. Ok: Product Orbit added successfully
  68. Ok: Product Rakia added successfully
  69. Ok: Product Dress added successfully
  70. Ok: Product Jacket added successfully
  71. Error: Product Milk already exists
  72. Ok: Product Eggs added successfully
  73. Ok: Product Cheese added successfully
  74. Ok: Jacket(49.9), Dress(121.9)
  75. Ok: Milk(1.9), Yogurt(1.9)
  76. Ok: Product CappyOrange added successfully
  77. Ok: Product Nestey added successfully
  78. Ok:
  79. Ok: Product Socks added successfully
  80. Error: Type fruits does not exists
  81. Ok: Product MacBookPro added successfully
  82. Ok: MacBookPro(1700.1234)
  83. Ok: Milk(1.9), Yogurt(1.9), CappyOrange(1.99), Eggs(2.34), Nestey(2.7), Socks(2.9), Cheese(5.55), Rakia(11.9), Jacket(49.9), Dress(121.9)
  84. Ok: Orbit(0.9), Milk(1.9), Yogurt(1.9), CappyOrange(1.99)
  85. Ok: Socks(2.9), Jacket(49.9), Dress(121.9)
  86. Input
  87. Copy
  88. add Milk 1.90 dairy
  89. add Yogurt 1.90 dairy
  90. add Notebook 1111.90 technology
  91. add Orbit 0.90 food
  92. add Rakia 11.90 drinks
  93. add Dress 121.90 clothes
  94. add Jacket 49.90 clothes
  95. add Milk 1.90 dairy
  96. add Socks 2.90 clothes
  97. filter by type dairy
  98. filter by price from 1.00 to 2.00
  99. filter by price from 1.50
  100. filter by price to 2.00
  101. filter by type clothes
  102. end
  103. Output
  104. Copy
  105. Ok: Product Milk added successfully
  106. Ok: Product Yogurt added successfully
  107. Ok: Product Notebook added successfully
  108. Ok: Product Orbit added successfully
  109. Ok: Product Rakia added successfully
  110. Ok: Product Dress added successfully
  111. Ok: Product Jacket added successfully
  112. Error: Product Milk already exists
  113. Ok: Product Socks added successfully
  114. Ok: Milk(1.9), Yogurt(1.9)
  115. Ok: Milk(1.9), Yogurt(1.9)
  116. Ok: Milk(1.9), Yogurt(1.9), Socks(2.9), Rakia(11.9), Jacket(49.9), Dress(121.9), Notebook(1111.9)
  117. Ok: Orbit(0.9), Milk(1.9), Yogurt(1.9)
  118. Ok: Socks(2.9), Jacket(49.9), Dress(121.9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement