回転パタン辞書順
doutonbori の回転パターンは
outonborid
utonborido
tonboridou
onboridout
nboridouto
boridouton
oridoutonb
ridoutonbo
idoutonbor
doutonbori
これらの中で辞書順では 'boridouton'
。
text = 'doutonbori'
# Initialize a variable to store the lexicographically smallest result
smallest_text = text
# Perform the transformation based on the length of the text
for _ in range(len(text)):
# Perform the rotation
text = text[1:] + text[0]
# Check if the current rotation is lexicographically smaller
if text < smallest_text:
smallest_text = text
# Display the smallest result
print(smallest_text)