#C14550. Separate Elements by Type
Separate Elements by Type
Separate Elements by Type
You are given a list of elements where each element may be an integer, a floating-point number, or a string. Your task is to separate the elements by their type.
Let \( n \) be the number of elements. Then the input consists of \( n \) lines, each containing one element. An element is considered an integer if it does not contain a decimal point and can be parsed as an integer, a float if it contains a decimal point and can be parsed as a floating-point number, and a string otherwise.
You should output a JSON object with three keys: "integers", "strings", and "floats". The value for each key is a list of the corresponding elements in the order they appear in the input.
inputFormat
The first line of input is an integer \( n \) which indicates the number of elements. The following \( n \) lines each contain one element. Elements that represent integers or floats will be given without extra formatting. Note that floats always contain a decimal point.
outputFormat
Output a JSON formatted dictionary with exactly three keys: "integers", "strings", and "floats". The values should be lists containing the integers, strings, and floats read from the input, respectively.
For example, if the input is:
8 1 apple 3.14 2 banana 5.5 carrot 7
Then the output should be:
{"integers": [1, 2, 7], "strings": ["apple", "banana", "carrot"], "floats": [3.14, 5.5]}## sample
8
1
apple
3.14
2
banana
5.5
carrot
7
{"integers": [1, 2, 7], "strings": ["apple", "banana", "carrot"], "floats": [3.14, 5.5]}