#P5734. Text Document Editor
Text Document Editor
Text Document Editor
You are required to develop a simple text document editor. Initially, you are given a string which represents the starting document. You may assume that the document's first character is at index \(0\). The editor supports the following operations:
1 str
: Append. Insert the string \(\texttt{str}\) at the end of the document, then output the entire document.2 a b
: Substring. Keep only the substring of the document starting from index \(a\) (0-indexed) with length \(b\), then output the new document.3 a str
: Insert. Insert the string \(\texttt{str}\) into the document before the character at index \(a\), then output the entire document.4 str
: Find. Find the first occurrence (lowest index) of the substring \(\texttt{str}\) in the document and output its index. If not found, output \(-1\).
For simplicity, the initial document and all \(\texttt{str}\) in the operations will not contain any spaces or newline characters. There will be at most \(q\) operations.
inputFormat
The first line contains the initial document (a non-empty string without spaces). The second line contains an integer \(q\) denoting the number of operations. The following \(q\) lines each contain an operation in one of the following formats:
1 str
2 a b
3 a str
4 str
All numeric values are integers and all \(\texttt{str}\) inputs are strings without spaces.
outputFormat
For each operation, output the result on a new line. For operations 1, 2, and 3, output the updated document string. For operation 4, output the starting index of the first occurrence of the given substring in the document, or \(-1\) if the substring is not found.
sample
hello
4
1 world
3 5 _
4 world
2 1 4
helloworld
hello_world
6
ello
</p>