Find The Successor
You are given a list of
strings. For each string in the list, you need to find the successor string from the same list (including the case when is equal to ). The successor string is the smallest string that appears at the beginning of string .
The first line of the input contains a single integer, (), representing the number of strings in the list.
The following lines contain the strings. Each string consists of lowercase English letters.
It is guaranteed that the total number of characters in the input does not exceed .
For each string in the input, output a single line containing the successor string .
5 abaca aba abacaba bacab dabacaba
aba aba aba bacab dabacaba
For the string “aba” the successor string is “aba” itself. For the strings “abaca” and “abacaba” the successor is “aba”. For the string “abcab” the successor string is “bacab”. For the string “dabacaba” the successor string is “dabacaba”
Time limit: 3.5 seconds
Memory limit: 512 MB
Output limit: 1 MB