b770. 47. Play with Words, Too.
Tags : 字串處理
Accepted rate: 11人/ 22人 ( 50%) [非即時]
評分方式:
Tolerant

最近更新 : 2016-01-13 14:11

Content

Write a program (again) to play with words. Your program should support the following commands.

  • insert left x n Insert n characters of x at the beginning of a word.
  • insert right x n Insert n characters of x at the end of a word.
  • insert k x n Insert n characters of x so that the first of them will become the k-th character of this word.
  • print
    Print the current content of the word in the following format: if the word is "gooooooooooooooooooooooooooogle", you should print "g 1 o 27 g 1 l 1 e 1 $". In other words, you should encode all consecutive sequences with the same character into character-length pairs, then print a dollar sign to indicate the end of the word.

Where x is a alphanumeric character and both n and k are positive integers.

Note that you need to implement this word as a binary tree, otherwise it it very likely that you will run out of time because you need to run through the data structure in order to find the correct location for insertion. You may want to store the number of characters in a node, as well as the number of characters in the subtree to speed thing up.

Input

The input data contains a sequence of commands described above. You may assume that all commands are valid. That is, k would not exceed the current length of the word plus 1. The total length of the word would less then 2147483647.

Output

You should output the content of the word in the compressed format described above whenever you read the "print" command.

Sample Input #1
print
insert left g 2
insert right e 1
insert 3 l 1
insert 2 o 2
print
insert 4 o 25
print
Sample Output #1
$
g 1 o 2 g 1 l 1 e 1 $
g 1 o 27 g 1 l 1 e 1 $
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (6%): 1.0s , <1K
公開 測資點#1 (6%): 1.0s , <1K
公開 測資點#2 (6%): 1.0s , <1K
公開 測資點#3 (6%): 1.0s , <1K
公開 測資點#4 (6%): 1.0s , <1K
公開 測資點#5 (6%): 1.0s , <1K
公開 測資點#6 (6%): 1.0s , <1M
公開 測資點#7 (6%): 1.0s , <1M
公開 測資點#8 (6%): 1.0s , <1M
公開 測資點#9 (6%): 1.0s , <10M
公開 測資點#10 (6%): 1.0s , <10M
公開 測資點#11 (6%): 1.0s , <10M
公開 測資點#12 (7%): 1.0s , <10M
公開 測資點#13 (7%): 2.0s , <10M
公開 測資點#14 (7%): 1.0s , <10M
公開 測資點#15 (7%): 1.0s , <10M
Hint :
Tags:
字串處理
出處:
NTU 批改娘 計算機程式設計課程 [管理者: morris1028 (碼畜) ]

Status Forum 排行

ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」