#C14839. Unique Words Extractor

    ID: 44532 Type: Default 1000ms 256MiB

Unique Words Extractor

Unique Words Extractor

You are given a list of strings. Your task is to extract all the unique words from these strings, ignoring case differences and excluding punctuation. A word is defined as a maximal sequence of alphanumeric characters. For example, the string "Hello, world!" contains the words "hello" and "world".

The program should read from standard input and write the result to standard output. The first line of input contains an integer n denoting the number of strings. Each of the following n lines contains one string. You must output all unique words extracted from the input, sorted in lexicographical order and separated by a single space. If no words are found, output an empty line.

Note: The extraction should deal with punctuation by treating any non-alphanumeric character as a separator and convert all letters to lowercase.

inputFormat

The input starts with a single integer n (n ≥ 0) on the first line which represents the number of strings. This is followed by n lines, each line being a string that may contain letters, digits, punctuation, and spaces.

Example:

2
Hello, world!
Hello again, world.

outputFormat

Output a single line containing the unique words extracted from the input, sorted in lexicographical order and separated by a single space. If there are no words, output an empty line.

Example:

again hello world
## sample
2
Hello, world!
Hello again, world.
again hello world