#K73922. Sort Custom Strings

    ID: 34083 Type: Default 1000ms 256MiB

Sort Custom Strings

Sort Custom Strings

You are given several strings. Your task is to sort these strings based on a custom criterion:

  • First, all strings that consist only of alphabetic characters (i.e. letters A–Z and a–z) should come.
  • Then, all remaining strings (those that contain digits or other non‐alphabet characters) should follow.
  • Within each group, the strings are sorted in lexicographic (dictionary) order.

Formally, if we denote by \(A\) the set of strings that satisfy isalpha(s)==true and by \(B\) the other strings, then the answer is given by:

\[ \text{answer} = \text{sort}(A) \;\Vert\; \text{sort}(B), \]

In addition, the input provided via standard input may include a final line with the text "END". If this line is present, it should be ignored.

inputFormat

The input consists of several lines, each containing one string. The last line may be the word "END" which should be ignored during processing.

outputFormat

Output the sorted strings to standard output, each on a new line.

## sample
HELLO
42WORLD
GOODBYE
A1B2C3
CHERRY
APPLE
BANANA
END
APPLE

BANANA CHERRY GOODBYE HELLO 42WORLD A1B2C3

</p>