M
M
Maxim2018-05-01 13:29:23
Python
Maxim, 2018-05-01 13:29:23

What sorting should be applied for words and numbers?

Characters at the input no more than 5000. I am not strong in algorithms (temporarily) and I need advice on which sort to use.
Example:

Input:
car truck 8 -4 bus 6 1
Output:
bus car -4 1 truck 6 8

The order of numbers and words must be preserved when sorting.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Olohtonov, 2018-05-01
@maximkv25

It is worth sorting numbers and words separately, remembering the positions of words and numbers in the input sequence, and then writing them to the output in accordance with this order.
It is worth sorting with a function built into the language, and not writing your own, if this is not required by the condition of the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question