#P1124. 文件压缩
文件压缩
Description
The algorithm is as follows: For a string of length , first construct strings, where the -th string is obtained by moving the first characters of to the end. Then sort these strings by their first character in ascending order; if two strings have the same first character, sort them by their positions in in ascending order. The last characters of the sorted strings form a new string , whose length is also and which contains every character of . Finally, output and the position of the first character of in .
Example: is example.
- Construct strings.
example
xamplee
ampleex
mpleexa
pleexam
leexamp
eexampl
- Sort the strings.
ampleex
example
eexampl
leexamp
mpleexa
pleexam
xamplee
- Compression result.
,。
Because of the characteristics of English words, certain letters occur very frequently, so identical letters are very likely to be grouped together in , which improves the compression ratio of . Although this algorithm leverages properties of English words, in practice it is found to work for almost all file compression.
Write a program that reads and , and outputs the string .
It is guaranteed that contains only lowercase letters (so the input also contains only lowercase letters).
Input Format
Three lines in total.
The first line contains an integer (), the length of .
The second line contains the string .
The third line contains an integer .
Output Format
One line, the string .
7
xelpame
7
example
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号