13089 - Another text editor   

Description

In this problem, we simulate a simple text editor. Given a series of keyboard input texts and commands, output the final text content.

 

The text editing rules are defined as follows:

  • Five special commands started with a backslash (/) character:
    1. (/I): The editing-mode changing command, which switches the mode between INSERT and REPLACE.
      1. Initially, the editor is in the INSERT mode. Then a /I command changes the mode to REPLACE, the next /I command changes the mode back to INSERT, and so on.
      2. The INSERT mode: insert the text after the cursor.
      3. The REPLACE mode:
        1. If there is a character after the cursor and it is a newline character, ***insert the text before the newline character*** (this is what we have in the existing PC operation);
        2. Otherwise, use the text to replace the existing content after the cursor.
    2. (/R /L): The two navigating commands, which move the cursor to the right or to the left;
    3. (/B): The backspace command, which deletes a character (letter, digit or newline) before the cursor;
    4. (/n): The newline command, which creates a new line after the cursor.

 

  • Normal alphabetical/numerical and whitespace input (A-Za-z0-9 and ' '): directly writes (inserts or replaces) after the cursor of the text content.

 

The keyboard input sequence will not exceed 600 characters, and the text content of the testcases will also not exceed 600 characters when simulating.

 

Hint1:

#include <stdio.h>

#define MAX_SIZE 600

char content[MAX_SIZE];
char input[MAX_SIZE];

int main()
{

    fgets(input, MAX_SIZE, stdin);

    /* your code here */

    printf("%s", content);

    return 0;
}

Hint2:

Testcase1 contains /B+/L
Testcase2 contains /R+/L+/B
Testcase3 contains /R+/L+/B+/n
Testcase4 contains /n+/R+/L+/B+/I
Testcase5 contains /n+/R+/L+/B+/I

Input

The keyboard input sequence, which is only one line (i.e., without a newline character at the end).

There is always a valid command (/B /n /L /R /I) right after the backslash character.

Output

The final text content.

Sample Input  Download

Sample Output  Download

Tags




Discuss