3137 - I2P(I)2024_Yang_lab9 Scoreboard

Time

2024/11/26 22:00:00 2024/11/26 22:01:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12109 Text Editor 2
14531 PrinPriPrin II

12109 - Text Editor 2   

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.

 

char *fgets( char *str, int numChars, FILE *stream );

The C library fgets function reads a string from the input stream argument and stores it in strfgets 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




14531 - PrinPriPrin II   

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.)

 

For the %d format, when using %Ad where A is a positive integer, if the number of digits is less than A, spaces will be added in front to make the total width equal to A.

 

Please process your string using the Gen function and output the result.
(You can modify the Gen function as long as you ensure the output result is correct.)

#include <stdio.h>

#include <string.h>

int Gen(int init, char *str){

    int mul = 37, mod = 1e9 + 7;
    long long ret = init, len = strlen(str);
    for (int i=0; i < len; i++){
        ret *= mul;
        ret += str[i];
        ret %= mod;
    }
    return ret;
}

Input

The first line contains an integer T, representing the number of signals.

The following T lines each contain a string S, 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, %d, %Ad, %f, %Bf formats
  • Not contain double quotes ( " ) inside printf strings

Constraints

  • 1 ≤ T ≤ 100
  • 1 ≤ |S | ≤ 104
  • 0 ≤ |N - M | ≤ 500
  • 0 ≤ A ≤ 15
  • 0 ≤ input integer ≤ 109

Subtasks

  • Testcases 1: printf appears in the input
  • Testcases 2: printf, for-loop appear in the input
  • Testcases 3: printf, for-loop%c appear in the input
  • Testcases 4: printf, for-loop%c%d appear in the input
  • Testcases 5 ~ 8: No additional restrictions.

Output

Output T lines, each containing a signal Safter being processed by the Gen function, representing the signal to process in the i-th round.

 

Please remember to print "\n" at the end.

 

Hint

If you are not sure how to use Gen, please refer to the following.

If the input is "printf(...);" , you can process it with the following code.
 
int main(){
 
    // your code
 

    int ans 0;

    ans = Gen(ans, <your string>);

    printf("%d\n", ans);
 
    return 0;
}

 

If the input is "for(int i=N; i < M; i++) printf(...);" , you can process it with the following code.

int main(){
 
    // your code
 

    int ans 0;

    for(int i=N; i < M; i++){

        ans = Gen(ans, <your string>);
    }
 
    printf("%d\n", ans);
 
    return 0;
}
 
For example, if the input is "for(int i=10; i < 14; i++) printf("I2P1 is very %d%c for me.", 1, 'z');"
You should use the second one, and 
N should be 10, M should be 14, and <your string> should be "I2P1 is very 1z for me."

Sample Input  Download

Sample Output  Download

Tags




Discuss