Here's a very important and basic problem in string:
Given a string S = s1s2s3...sl, define it's i-th rotation to be sisi+1...sls1...si-1.
So for example, if S = "bacaa", it's five rotations are: "bacaa", "acaab", "caaba", "aabac", "abaca".
Now the question is simple: given the string S, find among its all rotations the lexicographically smallest one. In the above example where S = "bacaa", the answer is "aabac".
p.s. see if you can solve it without using sophisticated data structure like suffix array!
The input consists of multiple test case, terminated by EOF. Each test case is simply the string S.
For each testcase, output the lexicograhically smallest rotation of the input string.
bacaa aaa zxcvbnm
aabac aaa bnmzxcv
Migrated from old NTUJ.
Classic
No. | Testdata Range | Score |
---|