编程介的小学生 2017-01-31 08:23 采纳率: 20.5%
浏览 723
已采纳

Pasting Strings

Description
You are part of a team implementing an HTML editor and have been tasked with the problem of implementing the cut/copy/paste functions. One of your goals is to preserve the formatting of selected text, even though that formatting may be determined by HTML tags outside the range of the actual selected text.

You will be provided with a block of formatted text, a starting position B, and an ending position E. Your program should output the text of the substring of that text from B (inclusive) to E (exclusive), prepending and appending formatting tags as necessary so that the output is well formed and has the same format as it had in its original position.

For the purposes of this problem, format tags consist of an opening tag (such as < b> "), followed by some text, followed by a closing tag (such as< / b> "). Opening and closing tags are paired (< /whatever> " closes< whatever> ") and are considered opened between the opening tag and the closing tag. A tag may not be closed unless it is the most recent unclosed tag (e.g., < i> abc< b> def< / i> ghi< / b> " is illegal). A tag may not be opened if it is already open (e.g.,< b> < b> recursive b< / b> < / b> " is illegal).

Input
Input data will consist of multiple test cases. Each test case will consist of one line of input of the form

B E TEXT

where B is an integer giving the (inclusive) beginning location of the substring, E is an integer giving the (exclusive) ending location of the substring, and TEXT contains the text from which to extract the substring. The TEXT begins after a single blank character immediately following E , and continues to the end of the line. B and E will be specified so that 0 <= B <= E <= length(TEXT) .

End of input will be signaled by the line ``-1 -1 " with a single space following the second -1.

No input line will be longer than 200 characters.

The TEXT will be composed of characters with an ASCII value >= 32 (the ASCII space) and <= 126 (the ASCII ' '). Opening tags will be of the form < X > " where X contains at least 1 character and is composed entirely of the characters `a' to `z', `A' to `Z', `0' to `9', and `-'. Closing tags will be of the form< /X > ". The character `< ' will only occur in the input as the first character of an opening or closing tag.

The input text will be well formed - all opening tags will be matched with a closing tag, all closing tags will match an opening tag, each closing tag will close the most recent unclosed tag, and tags will not be recursive (each tag must be closed prior to reopening).

0 <= B <= E <= length(TEXT) . Neither B nor E will reference a character that is part of an opening or closing tag except for the character `< '.

Output
For each test case your program should print a single line containing the substring of TEXT from B (inclusive) to E (exclusive), prepending the substring with opening tags and appending the substring with closing tags as necessary so that the output line is well formed and has the same set of open tags as when it was included in the original TEXT .

Sample Input

0 15 Testing!
18 23 100, 1000, 10000
4 4 123
0 16 :-/ :-> :-) :-<-> </->
-1 -1

Sample Output

Testing!
1000,

:-/ :-> :-) :-

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-06 15:45
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符