# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11269 | Text Editor |
|
14518 | PrinPriPrin |
|
Description
In this problem we simulate a simple text editor. Given a series of keyboard input, output the final text content.
The text editing rules are defined as following:
1. Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) directly write after the cursor of the text content.
And four special commands started with a backslash(/) character
2. The backspace command which deletes a letter before the cursor (/backspace)
3. The newline command which creates a new line after the cursor (/newline)
4. The two navigating commands which move the cursor (/left /right)
The size of the text content is fixed to 500 characters, and the text content of testcases will not exceed 500 characters when simulating.
Use fgets(). (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fgets-fgetws?view=msvc-170)
Hint:
#include <stdio.h> #define MAX_SIZE 500 char content[MAX_SIZE]; char input[MAX_SIZE]; int main() { fgets(input, MAX_SIZE, stdin); /* your code here */ printf("%s", content); return 0; }
Input
The keyboard input sequence.
There is always a valid command(/backspace /newline /left /right) right after the backslash character.
There is no newline character at the end
Output
The final text content.
Sample Input Download
Sample Output Download
Discuss
Description
You never believed in aliens until one day, while exploring a building rumored to have UFO sightings to win a bet with your friend. During a phone call with your friend, the signal became increasingly distorted. Suddenly, you lost consciousness. When you opened your eyes, three aliens with mechanical arms appeared before you in a strange space, with your limbs restrained.
Your friend, discovering your disappearance, uses Turbo Granny(高速婆婆)time-travel ability to reach you. To pinpoint your location, he sends signals that you need to respond to.
You will receive T signals S. You need to return the execution result of each line to your friend.
The signals will only appear in the following formats:
1. printf("<string>");
2. printf("<string>", '<char>' / <integer>, '<char>' / <integer>, ...);
3. for(int i=N; i < M; i++) printf(...);
(The printf format in the 3rd case follows the same pattern as cases 1 and 2.)
Input
The first line contains an integer T, representing the number of signals.
The following T lines each contain a string Si , representing the signal to process in the i-th round.
Each signal Si is guaranteed to:
- Not contain backslashes ( \ ) or single quotes ( ' )
- ( % ) only appears in %c and %d formats
- Not contain double quotes ( " ) inside printf strings
Constraints
- 1 ≤ T ≤ 200
- 1 ≤ |S | ≤ 104
- 0 ≤ |N - M | ≤ 1000
Output
Output T lines, each containing a signal Si , representing the signal to process in the i-th round.
Please remember to print "\n" at the end.
Hint
You can solve this problem using the fgets
function and some functions from the string.h
library.
- Use
fgets()
. (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fgets-fgetws?view=msvc-170) - Use
strtok()
. (https://cplusplus.com/reference/cstring/strtok/)