1045 : VIM

时间限制:1 Sec 内存限制:56 MiB 提交:6 正确:1

提交 状态 论坛

题目描述

Vim is a text editor which developed from vi. Due to its powerful function in code complete, compile, and error jump, it’s widely used by programmers. The same as Emacs, it’s the most popular text editor among users of UNIX. As such an excellent text editor, Vim has various of orders. Now, we’re asking you to write a program that simulates Vim’s replace order.

The format of Vim’s replace order is ([] means optional, {} means necessary) :
:[range]s/{pattern}/{string}/[flag]
In the order above,
‘:’ means the start of a replace order,
[range] indicates the range of the order, that is, the order works in which lines.
‘s’ is short for substitute.
{pattern} and {string} represent the string to match and replace to, respectively.
‘/’ is used to mark the beginning and ending of {pattern} and {string}.
{flag} is used to open or close some options.
{range} is often two integers separated by a comma, indicating the start line and end line’s line number.

Please write a program to simulate this simplified vim replace order.

输入描述

The input will consist of one case.

The first line will be a positive integer L (L <= 100), specifying the number of lines to be processed. Then L lines of text are given. Each line has no more than 100 characters.

After that, several pieces (<= 50) of replace orders are given (one per line). It is ensured that any line of text will never have more than 100 characters during the replacement.

输出描述

After the execution of every replace order, output the line number and content of the lines that have been replaced, order by line number from small to big. In each line, first output the line number, which has a width of 4 characters, right-aligned, then 2 spaces, then the text after replacement.

If any order replaced nothing, output "Pattern not found".

Output a blank line between any two replace order’s result.


样例输入

4
If the Tao is greet, then the operating system is greet.
If the operating system is greeter, then the compiler is greet.
If the compiler is greeter, then the applications is greet.
The user is pleased and there is harmony in the world.
:1,3s/greet/great/g
:%s//great/g 

样例输出

   1  If the Tao is great, then the operating system is great.
   2  If the operating system is greater, then the compiler is great.
   3  If the compiler is greater, then the applications is great.

Pattern not found 

来源

HDU