#K6551. Custom Word Sorting

    ID: 32213 Type: Default 1000ms 256MiB

Custom Word Sorting

Custom Word Sorting

You are given a single line containing a sequence of words separated by spaces. Your task is to sort the words in lexicographical order using a custom rule: for each character in a word, if two letters are the same when compared in a case‐insensitive manner, then the uppercase letter should come before the lowercase letter.

Formally, for each word, define the key for each character c as:

key(c)=(isLower(c),c)key(c)=\bigl(\mathbf{isLower}(c), c\bigr)

where \(\mathbf{isLower}(c)\) is 0 if \(c\) is uppercase and 1 if \(c\) is lowercase. The words should be sorted according to the lexicographical order of their keys. If the input is an empty string, simply output an empty string.

For example, consider the input "apple Banana apple orange ORANGE":

  • The sorted order is "Banana ORANGE apple apple orange".

Your function should read the input from stdin and print the result to stdout.

inputFormat

The input consists of a single line containing a string of words separated by spaces. The string may be empty. Each word contains only alphabet characters.

outputFormat

Output a single line containing the sorted words separated by a single space. If the input string is empty, output an empty string.

## sample
apple Banana apple orange ORANGE
Banana ORANGE apple apple orange