#P10526. [XJTUPC 2024] 命令行
[XJTUPC 2024] 命令行
Problem Description
There are pairwise distinct command strings (), each consisting only of lowercase letters. You need to implement a command line that supports command auto-completion.
Your input area is a string . It can accept lowercase letters , the key (denoted by ), the key (denoted by ), and the key (denoted by ). The rules are as follows:
-
When you receive a lowercase letter , append to the end of the input area string .
-
When you receive the key, it will try to delete the last character:
- If the input area string is empty, do nothing.
- If the input area string is not empty, discard the last character of .
-
When you receive the key, perform one smart completion on . The completion rules are:
- Let the set of command strings with prefix be .
- If is empty, do nothing.
- If is not empty, set to . Here means the longest common prefix, i.e., the longest string that is a prefix of every string in .
-
When you receive the key, it will try to execute the command :
- If there exists a command string , output the command index .
- If there is no command string , output .
- Whether the execution succeeds or not, clear the input area .
Given the input string that you receive, you need to output the result of each key execution.
Input Format
The first line contains two integers and (), the number of command strings and the length of the input string, separated by spaces.
The next lines each contain a string consisting only of lowercase letters, representing a command string. It is guaranteed that and all command strings are pairwise distinct.
The last line contains a string (), representing the input string. It is guaranteed that consists only of .
Output Format
Given the input string that you receive, you need to output the result of each key execution.
7 40
kill
killall
rm
rmdir
ifconfig
ifdown
ll
kTBlEkTaTEiTcBdTElTExjtuTExjtuBBBBBrTdTE
1 2 6 7 -1 4
Hint
Initially, the input area string .
After inputting , the input area string becomes .
After inputting , perform smart completion. At this time, , and . Therefore, the input area string becomes .
After inputting , the input area string becomes .
After inputting , the input area string becomes .
After inputting , since , you should output .
Translated by ChatGPT 5