#K86012. Grocery Store Management System

    ID: 36770 Type: Default 1000ms 256MiB

Grocery Store Management System

Grocery Store Management System

In this problem, you are required to build a basic grocery store management system. The system supports several commands:

1. ADD_USER <username> <user_type> - Adds a new user. Only two user types are allowed: 'customer' and 'admin'. If the user already exists or the user type is invalid, the command should return ERROR; otherwise, it returns SUCCESS.

2. ADD_PRODUCT <name> <category> <price> <quantity> - Adds a new product to the store with a given name, category, price, and stock quantity. If the product already exists, output ERROR; otherwise, output SUCCESS.

3. LIST_PRODUCTS [category] - Lists all products in the store. If a category is provided, only products belonging to that category should be listed. Each product is represented as a string in the format:

[ name\ category\ price\ quantity ]

4. PLACE_ORDER <username> <product_name> <quantity> - Places an order for a product. The order is successful only if the user exists, the product exists, and the available quantity is sufficient. On success, the product's quantity is reduced accordingly and the command returns SUCCESS; otherwise, it returns ERROR.

You will be given a list of commands to process. For each command, output the corresponding result on a new line.

inputFormat

The input starts with an integer N ((1 \leq N \leq 1000)) which denotes the number of commands to process. This is followed by N lines, each containing a command in one of the following formats:

- ADD_USER <username> <user_type>
- ADD_PRODUCT <name> <category> <price> <quantity>
- LIST_PRODUCTS or LIST_PRODUCTS <category>
- PLACE_ORDER <username> <product_name> <quantity>

Note: The price is a floating point number and quantity is an integer.

outputFormat

For each command, print the result on a separate line. For the command LIST_PRODUCTS, output each product on a new line in the format: name category price quantity (if there are multiple products, preserve the order of insertion).## sample

7
ADD_USER john customer
ADD_USER admin1 admin
ADD_PRODUCT Apple Food 1.2 100
ADD_PRODUCT Orange Food 0.8 50
LIST_PRODUCTS
PLACE_ORDER john Apple 10
PLACE_ORDER john Orange 60
SUCCESS

SUCCESS SUCCESS SUCCESS Apple Food 1.2 100 Orange Food 0.8 50 SUCCESS ERROR

</p>