Write a program to play with words. Your program should support the following commands.
insert left x
Insert character x at the beginning of a word.insert right x
Insert a character x at the end of a word.insert k x
Insert character x as the k-th character of this word.delete left
Delete a character at the beginning of a word.delete right
Delete a character at the end of a word.delete k
Delete the k-th character from the word.Where x is a character other than spaces, and k is a number starting from 1. Initially there is nothing in this word, and after the following command the word should be "bbaac"
.
command | word |
---|---|
insert left a | a |
insert left a | aa |
insert left b | baa |
insert right a | baaa |
insert right c | baaac |
insert left b | bbaaac |
delete right | bbaaa |
insert 4 c | bbacaa |
delete 5 | bbaca |
delete 4 | bbaa |
insert 5 c | bbaac |
The input data contains a sequence of commands described above. All commands are valid. For example, if your program receives a "delete 5"
command, we ensure that the word would has at least 5 characters for now.
After processing the input commands, Your program should find out all of the longest consecutive sequence with the same character from left to right and output the character of each sequence in order, then output the length of the sequences at the end. All data should be separated by a single space.
insert left a insert left a insert left b insert right a insert right c insert left b delete right insert 4 c delete 5 delete 4 insert 5 c
b a 2
編號 | 身分 | 題目 | 主題 | 人氣 | 發表日期 |
26736 | 406490150@gm ... (我是朱朱) | b771 | 541 | 2021-08-22 16:16 |