#C12083. Sorting Mixed Lists

    ID: 41471 Type: Default 1000ms 256MiB

Sorting Mixed Lists

Sorting Mixed Lists

You are given a list of items that can be one of three types: integers, floats, or digit‐strings. A digit‐string is a string that consists solely of digits (0-9). Your task is to sort this list according to the following rules:

  • All integers should come first, sorted in ascending order.
  • Next, all floats should appear, sorted in ascending order.
  • Finally, all digit‐strings should be listed, sorted in lexicographical order.

Formally, if the input list is \(L\), let \(I\) be the multiset of integer elements, \(F\) be the multiset of float elements, and \(S\) be the multiset of digit-strings. Then, the output should be the concatenation of the sorted sequence of \(I\), followed by the sorted sequence of \(F\), and finally the sorted sequence of \(S\).

Note that the input is provided via standard input (stdin) and the output should be sent to standard output (stdout).

inputFormat

The input consists of several lines. The first line contains a single integer \(n\) denoting the number of elements in the list. Each of the following \(n\) lines contains two tokens separated by a space. The first token is a type specifier which can be one of:

  • int — for an integer
  • float — for a floating-point number
  • string — for a digit-string (a string composed only of digits)

The second token is the value itself. For example:

8
int 3
string 45
float 2.5
int 1
int 99
float 7.75
string 3
float 12.5

outputFormat

Print the sorted list as a single line of space-separated values. The order must be all sorted integers first, then all sorted floats, and finally all sorted digit-strings.

For the sample input above, the output should be:

1 3 99 2.5 7.75 12.5 3 45
## sample
8
int 3
string 45
float 2.5
int 1
int 99
float 7.75
string 3
float 12.5
1 3 99 2.5 7.75 12.5 3 45