Task Description
有一個邊長為n的正方形棋盤,列(row)的編號由大寫英文字母組成、行(column)的編號則由小寫英文字母組成,順序不固定且字母不會重複出現。
棋格編號依序由列與行的編號組成,假設當前列編號為A、行編號為b,則該格編號為Ab。
現在請你照著下方程式碼與範例,用一個一維的字串陣列來表示棋盤中n*n個格子的編號。
Hint
必須使用「動態記憶體配置」
construct.h
打上 function header 以及相關的設定。
1 2 3 4 | #include <stdio.h>
#include <stdlib.h>
void Construct(char**, int);
|
construct.c
撰寫程式碼後對應上傳。
1 2 3 4 5 | #include "construct.h"
void Construct(char**board, int n) {
/ add your code /
}
|
main.c
這個檔案無法更改也無須上傳。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include "construct.h"
int main() {
int n = 0;
scanf("%d", &n);
char**board = (char**)malloc(n*n * sizeof(char*));
Construct(board, n);
for(int i = 0; i < n*n; i++) {
printf("%s ", board[i]);
if(i % n == n-1) printf("\n");
}
for (int i = 0; i < n*n; i++) {
free(board[i]);
}
free(board);
}
|
Input Format
輸入共有三行,
第一行是一數值n代表棋盤邊長(1 <= n <= 26)
第二行是長度為n的大寫英文字母字串,代表棋盤中列的編號(A-Z,順序不固定且每個字母只會出現一次)
第三行是長度為n的小寫英文字母字串,代表棋盤中行的編號(a-z,同上)
Output Format
輸出大小為n*n的棋格編號
Sample Input
Sample Output