#C13383. Strings in Alphabetical Order

    ID: 42915 Type: Default 1000ms 256MiB

Strings in Alphabetical Order

Strings in Alphabetical Order

Given a list of strings, identify all the strings whose characters appear in alphabetical order. A string \(s\) is said to be in alphabetical order if its characters are arranged in non-decreasing order, i.e. \(s = \text{sorted}(s)\). For example, the string "abc" is in alphabetical order, while "acb" is not.

Note: The comparison is case-sensitive.

For instance:

  • Input: ["abc", "xyz", "mnop"] → Output: ["abc", "xyz", "mnop"]
  • Input: ["abc", "acb", "xyz", "bca", "mnop", "qrst"] → Output: ["abc", "xyz", "mnop", "qrst"]
  • Input: ["acb", "bca"] → Output: []

inputFormat

The input is read from stdin and has the following format:

N
s1
s2
...
sN

Where:

  • N is an integer representing the number of strings.
  • s1, s2, ..., sN are the strings to be checked.

outputFormat

Output the strings (each on a separate line) that have their characters in alphabetical order. The order of the output should be the same as their appearance in the input. If no such string exists, output nothing.

## sample
3
abc
xyz
mnop
abc

xyz mnop

</p>