| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12568 | Reverse Linked List ver 2 |
|
| 13077 | Ranking System |
|
Description
Given several operations, push x, pop, print, reverse, create a linked list dynamicly.
- push x: Add one Node (with data = x) at the front of linked list.
- pop: Delete the Node at the front of linked list.
- reverse: reverse the current linked list
- print: output the linked list in given format.
You have to implement 3 functions:
1. void Push(Node** ptr_head,int x)
2. void Pop(Node** ptr_head)
3. void Reverse_List(Node** ptr_head)
Note: Modify the Node* head by Node** ptr_head


Input
There’re operations on several lines.
All operations are one of push x, pop, print, reverse.
It’s guaranteed that:
- Number of operations is less than 5,000,000
- Integer x is in [−1000,1000]
- The maximum length of linked list is less than 10,000.
Output
Output the linked list for every print.
Sample Input Download
Sample Output Download
Partial Judge Code
12568.cPartial Judge Header
12568.hTags
Discuss
Description
Ranking system is common in everyday life.
Such as shopping site, mobile game, project contest, etc.
You have a struct of Node and a Table store Node*:
There’re 3 kinds of operation:
INSERT score, name: AddNode*with (score, name) into Table.DELETE name: Delete theNode*with name in the Table.TOP x: Returnintarray contains the indices of top x Nodes in Table.
The rank ofNode*is defined below:- The higher score, the higher rank
- For those with same score, ranking by their names in lexicological order.
Your task is to complete these 3 operations in ranking system.
Please trace the main.c, function.h for the detail interface and implementation.
main.c
#include <stdio.h>
#include "function.h"
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 1000
#define MAX_LEN 100
int N = 0;
Node* Table[MAX_SIZE];
int main(){
for(int i=0; i<MAX_SIZE; i++)
Table[i] = NULL;
int K;
scanf("%d", &K);
char op[10];
while( K-- ){
// printf("K: %d\n", K);
scanf("%s", op);
if( strcmp(op, "INSERT" ) == 0 ){
int score;
char name[MAX_LEN+1];
scanf("%d %s", &score, name );
Insert(Table, N, score, name );
N++;
}
else if( strcmp(op, "DELETE" ) == 0 ){
char name[MAX_LEN+1];
scanf("%s", name);
Delete(Table, N, name );
N--;
}
else if( strcmp(op, "TOP" ) == 0 ){
int x;
scanf("%d", &x);
int* idxs = Top(Table, N, x);
printf("Top %d:\n", x);
for(int i=0; i<x; i++){
printf("%d %s\n", Table[idxs[i]]->score, Table[idxs[i]]->name );
}
free( idxs );
}
}
for(int i=0; i<MAX_SIZE; i++){
if( Table[i] != NULL ){
free(Table[i]->name);
free(Table[i]);
Table[i] = NULL;
}
}
return 0;
}
functin.h
// function.h
#ifndef __FUNCTION_H__
#define __FUNCTION_H__
typedef struct{
int score;
char* name;
} Node;
// Node* Table[MAX_SIZE];
// N = number of nodes in Table
void Insert( Node** Table, int N, int score, char* name );
void Delete( Node** Table, int N, char* name );
int* Top( Node** Table, int N, int x);
#endif
Input
There’s an integer K on the first line.
There’s 1 operation on the each of following K lines.
It’s guaranteed that:
- The # of elements in Table will not exceed 1000 during the process
- 1 ≤ The length of all names ≤ 100
- All names are distinct.
Output
Print the top x students in the Table for each TOP x operation.