13826 - The Missing eForms
|
Time |
Memory |
Case 1 |
1 sec |
5 MB |
Case 2 |
1 sec |
5 MB |
Case 3 |
1 sec |
5 MB |
Case 4 |
1 sec |
5 MB |
Case 5 |
1 sec |
5 MB |
Case 6 |
1 sec |
5 MB |
Case 7 |
1 sec |
5 MB |
Case 8 |
1 sec |
5 MB |
Case 9 |
1 sec |
5 MB |
Case 10 |
1 sec |
5 MB |
Description

At the beginning of the semester at National Pokemon University (NPU), every student is running around for the course extra selection (加簽). In the add-or-drop selection session (加退選時期), to enroll in a course, students must submit "eForms" to the teacher. Due to the limited classroom size, after the formal course selection session, the teacher would decide who is eligible to take the course from the eForm list.
Team Rocket! Prepare for trouble! And make it double! Unfortunately, Team Rocket had hacked into the school system, and messed up the order of the eForms! The serial numbers of the eForm list are now disorderly. They are just evil!
Help these poor pokemon restore the eForms' order - sorting them by the serial numbers!
This is a partial judge problem. You would only need to implement the function "eFormSort" to pass the problem.
Each eForm contains a serial number, a student ID, and a student name. The eForm list is given as a linked list (one node for each eForm). Your task is to make the serial numbers of that linked list in ascending order by changing the order of the eForms. The given program would output the status of each eForm, which can be either "Approved" or "Pending", after you sorted the eForm list.
Hint.
- Please notice that the memory is quite limited in this problem, and you need to sort the linked list directly by updating the "next" pointers of the nodes, instead of allocating too much extra space. The given program will check if you actually perform the required node sorting.
- There are many ways to sort the linked list, and you may refer to the following two simple approaches:
- Approach 1: Use the Bubble Sort Algorithm. In this way, we just need to implement the operation of swapping two nodes. You can refer to the following gif and pseudocode to know more about this approach.

- Approach 2: While traversing the linked list, if you expect a node to occur but it does not, just keep traversing backward to find the node and move it forward. You can refer to the following gif to know more about this approach.

Input
- The first line contains an integer N (1 ≤ N ≤ 5000) - the number of submitted eForms.
- Each of the next N lines represents an eForm:
- Format:
<serial number> <student ID> <student name> <eForm status>
- All of the serial numbers in the eForm list are distinct integer numbers between 1 and N
- 1 ≤ student ID ≤ 109
- 1 ≤ length of student name ≤ 1000, and the name only consists of lower-case and upper-case alphabets A-Z / a-z
- eForm status is either "Approved" or "Pending"
- For your convenience, in the given eForm list, the serial number of the first eForm must be 1.
- For the 30% of the test cases, the serial numbers of the given eForm list would be of the form "1, N, N-1, N-2, ..., 3, 2". That is, to solve this, you can just reverse the interval of [2, N].
Output
If you implement the function and sort the linked list correctly, the given program would output N lines - each of the lines represents an eForm in the input's format.
Partial Judge Code
13826.c
Partial Judge Header
13826.h
Tags