#K39847. Smallest Lexicographic Concatenation
Smallest Lexicographic Concatenation
Smallest Lexicographic Concatenation
You are given two non-empty strings word1 and word2. Your task is to concatenate them in such an order that the resultant string is the lexicographically smallest among the two possible concatenations. In other words, you need to compare the strings:
\( s_1 = word1 + word2 \) and \( s_2 = word2 + word1 \)
and output \( \min(s_1, s_2) \).
Note: The lexicographic order is the generalization of alphabetical order to sequences of characters.
inputFormat
The input consists of two lines. The first line contains the string word1 and the second line contains the string word2.
outputFormat
Output the lexicographically smallest concatenation of the two input strings.## sample
abc
xyz
abcxyz