#P4567. [AHOI2006] 文本编辑器
[AHOI2006] 文本编辑器
Description
These days, Keke is not playing with Kaka, because Keke is obsessed with making a simple and efficient text editor. Can you help him? To clarify the goal, Keke gives an abstract definition of a "text editor":
Move k: Move the cursor to the position after the -th character. If , move the cursor to the position before the first character of the text.Insert n (newline) S: Insert a string of length after the cursor, without moving the cursor. Here .Delete n: Delete the characters after the cursor, without moving the cursor. Here .Rotate n: Reverse the characters after the cursor, without moving the cursor. Here .Get: Output the one character after the cursor, without moving the cursor.Prev: Move the cursor one character to the left.Next: Move the cursor one character to the right.
Definitions:
- Text: A sequence of or more characters. Each character’s ASCII code is in the closed interval or is a newline character. That is, characters are all visible characters or spaces, or newlines.
- Cursor: A marker indicating a position in a text. It can be before the first character, after the last character, or between two adjacent characters.
- Text editor: A program that performs the above seven operations on a piece of text and a cursor within it. If the text is empty, we say the text editor is empty.
Write a program to:
- Create an empty text editor.
- Read a sequence of operation commands from the input file and execute them.
- For every executed
Getoperation, write the specified content to the output file.
Input Format
The first line of the input file contains the number of commands . The following lines contain the operations to execute. Except for newline characters, all characters in the input file have ASCII codes in the closed interval . There are no trailing spaces at the end of lines.
Output Format
Output the results corresponding to each Get command in the input file, in order, with no extra characters. Note: If the output of a Get command is a newline character, no additional newline is needed.
10
Insert 13
Balanced eert
Move 2
Delete 5
Next
Insert 7
editor
Move 0
Get
Move 11
Rotate 4
Get
B
t
Hint
For the input, we make the following assumptions:
- The number of
MOVEoperations does not exceed , the total number ofINSERT,DELETE, andROTATEoperations does not exceed , the number ofGEToperations does not exceed , and the total number ofPREVandNEXToperations does not exceed . - The total number of characters inserted by all
INSERToperations does not exceed (where ). - When executing
DELETE,ROTATE, andGET, there are always enough characters after the cursor.MOVE,PREV, andNEXTwill not move the cursor to an invalid position. - The input file has no errors.
Translated by ChatGPT 5
京公网安备 11011102002149号