#K38487. Alphabetical Word
Alphabetical Word
Alphabetical Word
You are given a list of words. Your task is to find the first word in the list such that its characters appear in alphabetical (i.e., non-decreasing) order. In other words, for a word \(w\) with characters \(w_1, w_2, \dots, w_k\), it should satisfy \(w_1 \le w_2 \le \cdots \le w_k\). If no such word exists, output NONE
.
Note: Each word consists of lowercase letters only. If multiple words fulfill the criterion, return the one that appears first in the list.
Examples:
- For the words ["abc", "aabb", "xyz", "bcad"], the output is "abc" because "abc" is in alphabetical order.
- For the words ["hello", "world", "python"], the output is "NONE" since none of the words has its characters in alphabetical order.
inputFormat
The input is given via standard input (stdin) and follows this format:
N word1 word2 ... wordN
Where:
N
is a non-negative integer representing the number of words.- Each of the next
N
lines contains a single word which consists of lowercase alphabetical characters. - If
N
is 0, there will be no words following, and the output should beNONE
.
outputFormat
Output via standard output (stdout) a single line containing the first word whose characters are in alphabetical order. If no such word exists, output NONE
.
1
abc
abc