# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13360 | Struct- Student |
|
13427 | The Queen and the King |
|
13428 | Connect Four (step by step) |
|
13429 | Struct - Matrix (2) |
|
Description
給定一個名為Student的struct,如下列所示:
Student
- char first_name[20]
- char last_name[20]
- char student_id[10]
- int age
再給定主要執行程式main.c (題號.c)、以及Header檔function.h (題號.h);請試著完成Header檔中未實現的函式:SetFirstName()、SetLastName()、SetStudentID()、SetAge()、GetFirstName()、GetLastName()、GetStudentID()、GetAge()
Methods:
- void SetFirstName(Student* student, char* f) - Should set student’s first_name to f
- void SetLastName (Student* student, char* l) - Should set student’s last_name to l
- void SetStudentId(Student* student, char* s) - Should set student’s student_id to s
- void SetAge(Student* student, int a) – Should set student’s age to a
- char* GetFirstName(Student* student) - Return student’s first_name
- char* GetLastName(Student* student) - Return student’s last_name
- char* GetStudentId(Student* student) - Return student’s student_id
- int GetAge (Student student) - Return student’s age
- void InitStudent(Student* student) – Use “Set Methods” to initialize student’s properties
- void PrintStudent(Student student) – Use “Get Methods” to print student’s properties
function.c
Input
輸入符合以下格式
First_name Last_name Student_ID Age
First_name、Last_name、Student_ID為字串;Age為整數
Note:
- First_name、Last_name、Student_ID不會超過字串的初始設定長度
- Age不會超過int的範圍
- 無需處理輸入
Output
輸出符合以下格式:
Student_ID, First_name Last_name, Age
Note:
- 輸出的最後必須要有一個換行符號 ('\n')
- 無需處理輸出
Sample Input Download
Sample Output Download
Partial Judge Code
13360.cPartial Judge Header
13360.hTags
Discuss
Description
在西洋棋中,每一顆棋子的移動方式都不太一樣。皇后可以移動的範圍最廣,它可以直著走、橫著走、以及斜著走,而且在沒有受到其他棋子的阻攔下,移動範圍沒有限制
(Excerpted from wiki: https://en.wikipedia.org/wiki/Chess)
給定一個8x8的西洋棋棋盤,並且在其中放置一個皇后棋子,以及一個國王棋子;在移動皇后的情況下,請試著將移動皇后後可不可以吃掉國王的狀態,在地圖當中標示出來 (包含當下所在的格子、以及可以直接吃掉國王的格子);特別注意的是,由於皇后無法穿越其他棋子,因此國王身後的格子不能列為計算。
舉例
若國王與皇后的位置,以及最後輸出的答案如下圖所示:
若國王出現在皇后的移動路徑中,則最後輸出的答案如下圖所示:
特別注意(4, 5)的格子,皇后可以直接吃掉國王,因此這格可以標記為勾;不過因為國王棋子的阻攔,皇后不能移動到(4,6)、(4,7),因此這兩格不能算成可以吃掉國王的格子
Note:
- 利用字元‘-’來代表棋盤中的空格
- 利用字元‘K’來代表棋盤中的國王
- 利用字元‘Q’來代表棋盤中的皇后
- 利用字元‘V’來代表棋盤中標記可以吃掉國王的位置
- 利用字元‘X’來代表棋盤中標記不可以吃掉國王的位置
- 字元之間存在著空格將其分開
Input
一個棋局格式;其中一定有一個國王,一個皇后
Output
輸出符合以下格式:
一個棋局格式,當中顯示皇后所有的路徑格子,以及標記可不可以吃掉國王的狀態
Note:
- 輸出的最後必須要有一個換行符號 ('\n')
Sample Input Download
Sample Output Download
Tags
Discuss
Description
“四子棋”是一個經典的桌上遊戲,桌面上有立著的屏風小盒子,盒子分成7欄6列,每一欄各有一個開口可以由上方投入小圓片;遊戲開始後,兩名玩家分別持不同顏色的小圓片,並依序從開口投入圓片;圓片受地心引力影響,會落至底部或其他圓片上;當其中一名玩家讓4枚連續的小圓片,以橫著、直著、斜著的任一種方式連成一線即獲勝
(Excerpted from wiki: https://en.wikipedia.org/wiki/Connect_Four)
給定一串數字,代表依序投入白黑圓片的欄位;請試著計算是哪一方獲勝,並印出最後的結果
舉例
輸入字串為:4 6 4 3 3 6 4 2 3 3 4 1 1 6 5
輸出:
o wins!
- - - - - - -
- - - - - - -
- - - x o - -
- - - o o - -
- - - o o - x
- - x x o - x
Note:
- 對局一律由白方('o')先開始
- 輸入的字串有可能包含多餘的步數;例如上述例子(4 6 4 3 3 6 4 2 3 3 4 1 1 6 5),從第12個輸出字元(第一個1出現的地方)開始之後的步數,因為白方已經獲勝,所以可以不用繼續印在棋盤上
- 輸入的字串不可能包含不合理的步數,例如:將圓片投入已經滿了的欄位中;也不會出現平手的局面
- 利用字元 ‘-’ 來代表棋盤中的空格
- 利用字元 ‘x’ 來代表棋盤中的黑方
- 利用字元 ‘o’ 來代表棋盤中的白方
Input
o1 x1 o2 x2 o3 x3 o4 x4...
Note:
- 以上整數代表黑白圓片投入的欄位數
- 數字和數字之間以空白隔開
Output
輸出比須符合以下格式:
p wins!
c c c c c c c
c c c c c c c
c c c c c c c
c c c c c c c
c c c c c c c
c c c c c c c
Note:
- 輸出的最後必須要有一個換行符號 ('\n')
- p為’x’、’o’其中一個字元
Sample Input Download
Sample Output Download
Tags
Discuss
Description
給定一個名為Matrix的struct,如下列所示:
Matrix
- int rowLength
- int colLength
- int *values
rowLength表示該矩陣的列數、colLength表示該矩陣的欄數、values則是用來記錄矩陣數值的一維陣列
給定主要執行程式main.c (題號.c)、以及Header檔function.h (題號.h);請試著完成Header檔中未實現的函式:Init()、Add()、Sub()、Mul();使的在獲得任兩個矩陣後,可以計算出其相加、相減、相乘的結果,並將它們印出來(如何印出矩陣已寫在function.c中,請直接使用)
Methods:
- void Init(Matrix *m, int _rowLength, int _colLength) – 將傳入的矩陣指標m的rowLength值設定為_rowLength、colLength值設定為_colLength、並動態規劃一個長度為_rowLength * _colLength的一維陣列
- void Add(Matrix m1, Matrix m2) – 印出”Matrix 1 + Matrix 2:\n”字串,並將兩個矩陣相加,最後使用Print()將結果印出來;當兩個矩陣的無法相加時,則印出” Uncalculable\n”
- void Sub(Matrix m1, Matrix m2) – 印出”Matrix 1 - Matrix 2:\n”字串,並將兩個矩陣相減,最後使用Print()將結果印出來;當兩個矩陣的無法相減時,則印出” Uncalculable\n”
- void Mul(Matrix m1, Matrix m2) – 印出”Matrix 1 * Matrix 2:\n”字串,並將兩個矩陣相乘,最後使用Print()將結果印出來;當兩個矩陣的無法相乘時,則印出” Uncalculable\n”
Note:
- 當兩個矩陣的row長度相等,且column長度也相等時,兩個矩陣才能進行加減
- 當第一個矩陣的column長度和第二個矩陣的row長度相等時,兩個矩陣才能進行相乘
function.c
Input
輸入符合以下格式
r1 c1
(r1 * c1)
r2 c2
(r2 * c2)
Output
輸出符合以下格式
Matrix 1 + Matrix 2:
(m1 + m2)
Matrix 1 - Matrix 2:
(m1 - m2)
Matrix 1 * Matrix 2:
(m1 * m2)