#C14792. Segregate Data Types
Segregate Data Types
Segregate Data Types
You are given a list of elements where each element is provided on its own line along with its type. The allowed types are:
- int for integers
- float for floating-point numbers
- string for strings
Your task is to segregate the input elements into three separate groups according to their types. If an element has a type that is not supported (for example, dict
or any other), you must immediately output an error message and stop further processing.
Details
The input is given from standard input (stdin
) as follows:
- The first line contains a non-negative integer n indicating the number of elements.
- Each of the next n lines contains two tokens separated by a space. The first token is a string representing the type (
int
,float
, orstring
) and the second token is the value.
If an unsupported type is encountered, output the error message in the exact format:
Error: Unsupported data type: X
, where X is the unsupported type, and terminate the program.
Output
Print three lines to standard output (stdout
):
- The first line contains all integers (in their original order) separated by a space. If there is no integer, output an empty line.
- The second line contains all strings separated by a space (or an empty line if none).
- The third line contains all floats separated by a space (or an empty line if none).
Note: Do not output any extra characters or whitespace other than as specified.
inputFormat
The input begins with an integer n on the first line indicating the number of elements. Each of the following n lines contains two tokens separated by a space:
- The first token is the type (
int
,float
, orstring
). - The second token is the value.
For example:
6 int 1 string hello float 3.5 int 4 string world float 2.718
outputFormat
The output consists of three lines:
- The first line contains all integers (in order) separated by spaces.
- The second line contains all strings (in order) separated by spaces.
- The third line contains all floats (in order) separated by spaces.
If a particular type is not present, output an empty line for that type. In case of an unsupported data type, output only the error message in the following format:
Error: Unsupported data type: X
where X
is the unsupported type from the input.
6
int 1
string hello
float 3.5
int 4
string world
float 2.718
1 4
hello world
3.5 2.718
</p>