#C12495. Retrieve Order Details

    ID: 41928 Type: Default 1000ms 256MiB

Retrieve Order Details

Retrieve Order Details

You are given an order identifier and a list of orders. Each order is represented as a JSON object containing at least the following keys:

  • id: an integer representing the unique order ID,
  • user: a string representing the username,
  • products: a list of strings representing product names,
  • total_amount: a number (float) representing the total amount for the order.

Your task is to retrieve the order whose id equals the given order id. If such an order exists, output its JSON representation; otherwise, output None.

Note: If the provided order id is not a valid integer then consider it invalid and output None.

The solution should read its input from standard input (stdin) and produce its output to standard output (stdout).

In mathematical terms, if we define a function \(f: \mathbb{Z} \times \mathcal{O} \to \mathcal{O} \cup \{None\}\) where \(\mathcal{O}\) is the set of order objects, then:

\[ f(id, orders)=\begin{cases}\text{order object} &\text{if there exists an order } o \text{ with } o.id = id\\None &\text{otherwise}\end{cases} \]

inputFormat

The input consists of two lines:

  1. The first line is a string representing the order id. It should represent a valid integer. If not, consider it invalid.
  2. The second line is a JSON array representing the list of orders. Each order is a JSON object containing the keys id, user, products, and total_amount.

outputFormat

If an order with the given id is found, output its JSON representation (without extra spaces). Otherwise, output None (without quotes).

## sample
1
[{"id": 1, "user": "Alice", "products": ["Book"], "total_amount": 12.99}, {"id": 2, "user": "Bob", "products": ["Pen", "Notebook"], "total_amount": 5.49}]
{"id":1,"user":"Alice","products":["Book"],"total_amount":12.99}