#C3710. Categorize Elements by Data Type

    ID: 47168 Type: Default 1000ms 256MiB

Categorize Elements by Data Type

Categorize Elements by Data Type

Given a list of elements of various data types, your task is to categorize the elements by their type. Each element in the input comes with a type identifier and a corresponding value. The possible type identifiers are:

  • int: Integer numbers.
  • float: Floating-point numbers.
  • bool: Boolean values; the value will be either true or false.
  • str: Strings without spaces.
  • list: A list of strings. In this case, after the type identifier the next token is an integer m (the number of items), followed by m string tokens.
  • None: Represents a null value.

You should output a JSON object (dictionary) where the keys are the type names (as strings: "int", "float", "bool", "str", "list", "None") and the corresponding value for each key is a JSON array containing all elements of that type (in the order they appear in the input). Note that the output must use valid JSON representation: numbers remain numbers (without quotes), booleans are in lowercase (true/false), strings are enclosed in double quotes, and None is represented as null.

The solution in every language must read from stdin and print the result to stdout.

inputFormat

The input is given from standard input (stdin) as follows:

The first line contains an integer nn denoting the number of elements. Then follow nn lines, each describing one element. Each element description begins with a type identifier (one of "int", "float", "bool", "str", "list", "None").

For types int, float, bool, and str, the type identifier is followed by a space and then the element value. For type list, the line contains the word "list", a space, an integer mm (number of items), and then mm tokens (each a string) separated by spaces. For type None, there is nothing after the type identifier.

outputFormat

Print a JSON object (dictionary) to standard output (stdout). The keys should be the type names ("int", "float", "bool", "str", "list", "None") and the values should be arrays containing the elements of that type. Each element must be represented in valid JSON: integers and floats as numbers, booleans as true or false, strings enclosed in double quotes, lists as JSON arrays (of strings), and None as null.## sample

7
int 1
str a
float 3.14
bool true
list 2 b c
None
int 2
{"int": [1,2], "str": ["a"], "float": [3.14], "bool": [true], "list": [["b","c"]], "None": [null]}