1605 - I2P(II)2019_Lee_HW1 Scoreboard

Time

2019/02/27 14:07:00 2019/04/02 17:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

11270 - reverse linked list   

Description

Given a link list structure named Node.

 

typedef struct _Node {

    int data;

    struct _Node *next;

} Node;

Use this structure to implement a reversing linked list.

 

You will be provided with main.c and function.h, and asked to implement function.c.

For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

Input

The input contains a sequence of positive integers as the linklist and the order, except the last one, which is -1, indicating the end of the sequence. 

Output

The output contains the sequence of resulting linklist.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11270.c

Partial Judge Header

11270.h

Tags




Discuss




11339 - linked list-insert, erase and remove   

Description

This problem will ask you to do some operations on a list. These operations contains insert, erase, print, remove and show. The position of first node is 0.

Input

The input consist of a number of operations. The first line specifies a non-negative integer N that specifies the number of operations. Each operations (I, E, P, R and S) are separated by a newline character (\n).

I stands for “insert”, following by a non-negative integer (insert position) and a non-negative integer (insert value, 0<=insert value<65536). Insert a node at insert position with insert value.

E stands for “erase”, following by a non-negative integer (start position) and a non-negative integer (end position). End position must be greater than or equal to start position. Erase multiple nodes from start position to end position (excluding end position). If start position is equal to end position, do not erase end position.

If any input positions in the two operations above is greater than or equal to the length of the list, treat the input position as the next position of the last position at the list.

For example, input is

I 0 0

I 1 1

S

Output should be

0 1

P stands for “print”, following by a non-negative integer (print position). Print the value of the node at print position.

If print position is greater than or equal to the length of the list, treat the input position as the last position at the list.  If the
linked list is empty, do not print anything.

R stands for “remove”, following by a non-negative integer (remove value). Remove the nodes in the list with the value that is equal to remove value.

S stands for “show”. Print the value of all nodes in the list. Separate every prints by a whitespace character. If the list is empty, do not print anything.

For example, input is

5

E 1 1

E 1 2

P 2

R 1

S

Output should be nothing.

Output

Print a space after doing P or S operations (if P or S has printed something).

Sample Input  Download

Sample Output  Download

Partial Judge Code

11339.c

Partial Judge Header

11339.h

Tags




Discuss




11345 - Josephus Problem using doubly circular linked list   

Description

Based on the original Josephus Problem introduced in class, an additional rule of this problem is to change

direction of counting after killing a person.  For example, there are 8 people, numbered 1 to 8, in a circle

and arranged in clockwise.  The step to kill is 3. 

The sequence of killing people is

1, 2, 3 (kill 3, change the direction to counter-clockwise)

2, 1, 8 (kill 8, change the direction to clockwise)

1, 2, 4 (kill 4, change the direction to counter-clockwise)

2, 1, 7 (kill 7, change the direction to clockwise)

1, 2, 5 (kill 5, change the direction to counter-clockwise)

2, 1, 6 (kill 6, change the direction to clockwise)

1, 2, 1 (kill 1)

 

So the person numbered 2 is the survivor.

 

You're asked to solve this problem using circular linked list.

You will be provided with main.c and function.h, and you need to implement function.c.

 

Note there is a time limit to solve this problem: 3 seconds.

Note that you can use the following partial code.

#include <stdio.h>
#include <stdlib.h>
#include "function.h"

man* createList(int n){
    
    int i;
    man* curr;
    head = (man*)malloc(sizeof(man));
    curr = head;
    curr->id = 1;
    for(i=2; i<=n; i++){
        curr->next = (man*)malloc(sizeof(man));
        curr->next->prev = curr;
        curr = curr->next;
        curr->id = i;
    }
    curr->next = head;
    head->prev = curr;

    return head;
}


int solveJosephus(int step){

}

Input

The input has two integers, n and m, where n is the number of total people, and m is the step to kill.

Output

The output is an integer: the survivor's number.  There is a newline after that.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11345.c

Partial Judge Header

11345.h

Tags




Discuss