#C11534. Alphabetical Word Sorter

    ID: 40861 Type: Default 1000ms 256MiB

Alphabetical Word Sorter

Alphabetical Word Sorter

Given a string that consists of letters, spaces, and punctuation marks (specifically comma ",", semicolon ";", period "."), your task is to extract all the words, sort them in lexicographical order, and output the sorted words separated by a single space.

Note that:

  • Punctuation marks and spaces should be considered as delimiters.
  • Empty tokens should be ignored.
  • The sorting order follows the standard lexicographical order (i.e. according to the ASCII values of characters). In particular, uppercase letters are considered different from lowercase letters.

For example, given the input string "hello,world;this.is a test", the extracted words are ["hello", "world", "this", "is", "a", "test"]. After sorting, they become ["a", "hello", "is", "test", "this", "world"], which should be output as a hello is test this world.

In mathematical terms, if we denote the input string as \(S\), and the set of delimiters as \(D = \{ ' ', ',', ';', '.' \}\), then the extraction of words can be represented by splitting \(S\) on any character in \(D\):

\[ \text{words} = \{ w \mid w \text{ is a non-empty substring of } S \text{ split by any } d \in D \} \]

Finally, order the list \(\text{words}\) in ascending order, and output the resulting sequence joined by a single space.

inputFormat

The input consists of a single string read from stdin. This string may contain letters, spaces, commas, semicolons, and periods.

outputFormat

Output a single line to stdout containing the sorted words, each separated by a single space. If no valid word exists, output an empty string.

## sample
hello,world;this.is a test
a hello is test this world