# 10056. Sort Table

## 題目描述

### 範例說明

A 表單為

name\score ex1 ex2 ex3
pangfeng 100 100 99
morris 0 0 100

• 例如按照 (ex1, ex2, ex3) 則表示先按照 ex1 進行降排序，相同時再按照 ex2，再相同最後是 ex3。最後輸出結果即為

pangfeng, 100, 100, 99morris, 0, 0, 100

• 例如按照 (ex3, ex1, ex2) 則表示先按照 ex3 進行降排序，相同時再按照 ex1，再相同最後是 ex2。最後輸出結果即為

morris, 0, 0, 100pangfeng, 100, 100, 99


### 實作細節

• void init(ExamTable *self, int n);
初始化某個表單且成績欄位恰好 n 個。
• void addrow(ExamTable *self, char *name, int score[]);
增加某個表單的資料。
• void print(ExamTable *self, int order[]);
根據 order 給定的順序進行排序後輸出。若成績都一樣，最後按照名字字典順序由小排到大。請參考範例輸出。

### main.c

12345678910111213141516171819202122232425262728293031#include "pangfeng.h"#include <stdio.h>#include <stdlib.h> int main() {    const int MAXETB = 8;    int etb_n, dim_n;    int cmds, cmd, tid, score[128], sort_order[128];    char sid[32];    ExamTable *etb = (ExamTable*) malloc(sizeof(ExamTable)*MAXETB);    scanf("%d", &etb_n);    for (int i = 0; i < etb_n; i++) {        scanf("%d", &dim_n);        init(&etb[i], dim_n);    }    scanf("%d", &cmds);    for (int i = 0; i < cmds; i++) {        scanf("%d %d", &cmd, &tid);        if (cmd == 1) {            scanf("%s", sid);            for (int j = 0; j < etb[tid].dim_n; j++)                scanf("%d", &score[j]);            addrow(&etb[tid], sid, score);        } else {            for (int j = 0; j < etb[tid].dim_n; j++)                scanf("%d", &sort_order[j]);            print(&etb[tid], sort_order);        }    }    return 0;}


## 範例輸入

23 4101 0 pangfeng 100 100 991 0 morris 0 0 1002 0 0 1 22 0 2 0 11 1 hank 5 5 6 61 1 scott 5 7 6 61 1 ahmad 5 5 6 72 1 0 1 2 32 1 3 1 2 02 0 2 0 1


## 範例輸出

----- table begin -----pangfeng, 100, 100, 99morris, 0, 0, 100----- end         ---------- table begin -----morris, 0, 0, 100pangfeng, 100, 100, 99----- end         ---------- table begin -----scott, 5, 7, 6, 6ahmad, 5, 5, 6, 7hank, 5, 5, 6, 6----- end         ---------- table begin -----ahmad, 5, 5, 6, 7scott, 5, 7, 6, 6hank, 5, 5, 6, 6----- end         ---------- table begin -----morris, 0, 0, 100pangfeng, 100, 100, 99----- end         -----