Sie sind auf Seite 1von 3

/

***********************************************************************************
********
Bob and Editor
Bob is working on his college project. He tried to make an editor like Vim, but he
came up with some messed editor which will follow only following commands :

dd -- delete the current line and move the cursor to the end of next line. If
there is no next line, move the cursor to end of the previous line. If all the
lines are deleted, move the cursor to the start of the first line.

:m -- move the cursor to the end of line m

i m -- each following m lines contain text to insert.

y -- copy the current line and replace the content of the buffer with the copied
line.

p -- paste the content of the buffer (the copied line) at the end of the current
line and move the cursor to the end of the line. If no line is copied, ignore this
command.

dy -- it will work similar to command dd and also copy the deleted line and replace
the content of the buffer with the copied line.

You are given some initial text T and Q commands. You are required to print the
final text after applying the given commands on T. Initially, the cursor is present
at the end of the last line and the buffer is empty.

Input :

The first line of input contains an integer N, number of lines in the initial text
T.
Next N lines contain the content of T.
Next line contains Q, denoting the number of commands.
It is followed by Q commands.
Output :

Print the final text T after applying the Q commands.


Constraints :

Sample Input
2
Nikunj
Khokhar
6
dd
dd
i 2
Yes
NO
:1
dd
i 2
No WAY
BETTER OPTIOn
Sample Output
NONo WAY
BETTER OPTIOn
Explanation
Initial text T is

Nikunj
Khokhar
The first command is dd which will delete the last line. So the text T will be

Nikunj

The second command is dd which will delete the one line and the cursor will move to
the start of the first line since all the lines are deleted.

The third command is i 2, which will add the next two lines in the text T. So the
text T will be

Yes
NO

The next command is :1 which will move the cursor to the end of the first line.

The next command is dd which will delete the first line and the cursor will move to
the end of next line. So the text T will be

NO

The last command is i 2 which will add the next two line in the text. So the text T
will be

NONo WAY

BETTER OPTIOn

NOTE: There are multiple input files and the time limit is 1 sec for each input
file.

Note: Your code should be able to convert the sample input into the sample output.
However, this is not enough to pass the challenge, because the code will be run on
multiple test cases. Therefore, your code must solve this problem statement.
Time Limit: 1.0 sec(s) for each input file
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded if any testcase passes
Allowed Languages: C, C++, C++14, Java, Java 8
***********************************************************************************
********/
#include <stdio.h>

#define N_MAX 100


#define Q_MAX 100
#define LINE_SIZE_MAX 1100

typedef struct line {


char text[LINE_SIZE_MAX];
int size;
}line_t;

int main ()
{
int n;
int q;
line_t textLines[N_MAX]

scanf ("%d", &n);


for (i=0 ; i<n ; i++) {
}

scanf ("%d", &q);


for (i=0 ; i<q ; i++) {
}

// final editor buffer will be array of structure pointers.


//

Das könnte Ihnen auch gefallen