编程介的小学生 2016-12-21 08:51 采纳率: 20.5%
浏览 874
已采纳

Checking the Text

Description

Wind's birthday is approaching. In order to buy a really really fantastic gift for her, Jiajia has to take a boring yet money-making job - a text checker.

This job is very humdrum. Jiajia will be given a string of text what is English letters and he must count the maximum number of letters that can be matched, starting from two position of the current text simultanously. The matching proceeds from left to right, one character by one.

Even worse, sometimes the boss will insert some characters before, after or within the text. Jiajia wants to write a program to do his job automatically, this program should be fast enough, because there are only few days to Wind's birthday.
Input

The first line of input file contains initial text.

The second line contains then number of commands n. And the following n lines describe each command. There are two formats of commands:

I ch p: Insert a character ch before the p-th. if p is larger than the current length of text, then insert at end of the text.

Q i j: Ask the length of matching started from the i-th and j-th character of the initial text, which doesn't include the inserted characters.

You can assume that the length of initial text will not exceed 50000, the number of I command will not exceed 200, the number of Q command will not exceed 20000.
Output

Print one line for each Q command, contain the max length of matching.
Sample Input

abaab
5
Q 1 2
Q 1 3
I a 2
Q 1 2
Q 1 3
Sample Output

0
1
0
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-24 16:15
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据