# | Problem | Pass Rate (passed user / total user) |
---|---|---|
12109 | Text Editor 2 |
|
14119 | Most Valuable Sentence II |
|
Description
In this problem we simulate a simple text editor. Given two lines of keyboard input texts and commands, output the final text content.
The text editing rules are defined as following:
1.
Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) in the first line.
And a series of two special commands started with a backslash(/) character in the second line.
2.
The backspace command which deletes a letter before the cursor (/b)
3.
The navigating command which move the cursor to the right(/r)
4.
The cursor is at the beginning of the text initially.
For example, for the following input:
The quick brown fox jumps over the lazy dog
/b/r/r/r/b
You should first store the "The quick brown fox jumps over the lazy dog" in the input char array and set cursor=0.
Then you can simulate the operation of the text editor.
The size of the text content is less than or equal to 500 characters, and there will be less than or equal to 500 commands when simulating.
The C library fgets
function reads a string from the input stream
argument and stores it in str
. fgets
reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to numChars
- 1, whichever comes first. The result stored in str
is appended with a null character. The newline character, if read, is included in the string.
Hint:
#include <stdio.h> #define MAX_SIZE 1005 char content[MAX_SIZE]; char input[MAX_SIZE]; char command[MAX_SIZE]; int main() { fgets(input, MAX_SIZE, stdin); fgets(command, MAX_SIZE, stdin); /* your code here */ printf("%s", content); return 0; }
Input
The first line is the text content which should be edited.
The second line is the commands.
There is always a valid command(/b /r) right after the backslash character.
Output
The final text content, and there should be no '\n' at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In a new debate among a group of N individuals, they've met a different criterion. If two individuals express sentences of equal value, precedence will be given to the elder among them, as age often signifies more life experience.
The value of a sentence remains the same as in the previous problem, whoever mentioned the the keyword the most in their sentences would be considered the most valuable. However, when individuals presented sentences of equal value, the deciding factor became the order of their age, if they're also in the same age, it would become the order in which they spoke.
Hint:
/* strtok example */
#include <stdio.h>#include <string.h> int main () { char str[] ="- This, a sample string."; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok (str," ,.-"); while (pch != NULL) { printf ("%s\n",pch); pch = strtok (NULL, " ,.-"); } return 0; }
Output:
Splitting string "- This, a sample string." into tokens: This a sample string
Input
The first line contains an integer N and a keyword.
Each of the next N lines represents a person in the following format:
the concatenation of "Name:<name>", "Age:<age>" and "Sentence:<sentence>", separated by semicolon ';'
where <name>, <age>, <sentence> represent a person's name, age, and the sentence he delivered, respectively.
Notice that name, age, and sentence may not appear in order.
len(keyword) <= 1000, N <= 1000, length of each line <= 100000
keyword is only composed by english letters.
<name> is composed by english letters and spaces.
<age> is an integer between [1, 100].
<sentence> is composed by english letters, spaces, and ",.?!" these four punctuation marks.
For testcase 1, 2: <name>, <age>, and <sentence> would appear in order, length of <name> would be 100, length of <age> would be 2, and length of <sentence> would be 10000
For testcase 3, 4: <name>, <age>, and <sentence> would appear in order
For testcase 5, 6: length of <name> would be 100, length of <age> would be 2, and length of <sentence> would be 10000
For testcase 7, 8: no other restriction
Output
If the k-th person delivered the most valuable sentence, please output like this:
<namek>: <sentencek>
There is a space after ':' and a '\n' in the end.