| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 5700 | mid2_Exercise1_矩陣相乘 |
|
| 5701 | mid2_Exercise2_大數加法 |
|
| 5702 | mid2_Exercise3_Knight's Move |
|
| 5703 | mid2_Exercise4_Numbers Tower |
|
| 5704 | mid2_Exercise5_Equivalent Sets |
|
| 5705 | mid2_Exercise6_Sentence reversal |
|
| 5706 | mid2_Exercise7_多項式相加 |
|
Description
底下是部分程式碼
#include
int main(void)
{
double A[10][10] = {0};
double B[10][10] = {0};
double C[10][10] = {0};
int A_r, A_c, B_r, B_c;
int i, j, k;
scanf("%d%d", &A_r, &A_c);
for (i=0; i for (j=0; j scanf("%lf", &A[i][j]);
}
}
scanf("%d%d", &B_r, &B_c);
for (i=0; i for (j=0; j scanf("%lf", &B[i][j]);
}
}
/* ??? */
for (i=0; i for (j=0; j printf("%5.2f ", C[i][j]);
}
printf("
");
}
return 0;
}
Input
矩陣A的row 矩陣A的col
矩陣A的內容
矩陣B的row 矩陣B的col
矩陣B的內容
Output
A x B的內容
Sample Input Download
Sample Output Download
Tags
Discuss
Description
#include#include #include #define END_INT 999 void string_to_int(char *str, int num[]); void show_big_int(int *num); void add(int num1[], int num2[], int num3[]); int main(void) { char str[100]; int A[100] = {0, END_INT}; int B[100] = {0, END_INT}; int C[101] = {0, END_INT}; FILE *fin; fin = fopen("big_int.txt", "r"); if (fin == NULL) { perror("big_int.txt"); exit(EXIT_FAILURE); } fscanf(fin, "%99s", str); string_to_int(str, A); fscanf(fin, "%99s", str); string_to_int(str, B); show_big_int(A); printf(" "); show_big_int(B); printf(" "); add(A, B, C); show_big_int(C); printf(" "); fclose(fin); return 0; } void string_to_int(char *str, int num[]) { int i; for (i=0; i
Input
兩組由數字所構成且長度不超過100的字串
Output
相加後的結果
Sample Input Download
Sample Output Download
Tags
Discuss
Description
已知西洋棋規則中
騎士一共有如下圖的八種走法

給定兩個 8 x 8 棋盤上的點 (X1, Y1)、(X2, Y2)
請算出騎士從 (X1, Y1) 最少需要走幾步可以到 (X2, Y2)
註:
1. (X1, Y1) 一定走得到 (X2, Y2)
2. 從 (X1, Y1) 走到下一個點才算第一步,(X1, Y1) 自己本身不是第一步
hint:
#include#define INF 2147483647 #define SIZE 8 /* 騎士的八種走法 每一列代表一種走法 x 和 y 的位移量 */ int Move[8][2] = { 1, -2, 2, -1, 2, 1, 1, 2, -1, 2, -2, 1, -2, -1, -1, -2 }; int X1, Y1; int X2, Y2; int min; int valid(int board[SIZE][SIZE], int x, int y, int path); void knightMove(int board[SIZE][SIZE], int x, int y, int step); int main() { /* board 記錄每一格走過了沒 */ int board[SIZE][SIZE] = {0}; while (scanf("%d %d %d %d", &X1, &Y1, &X2, &Y2) != EOF) { min = INF; if (X1==X2 && Y1==Y2) { printf("0\n"); } else { /* 注意!!! board內的順序為Y、X */ board[Y1][X1] = 1; knightMove(board, X1, Y1, 1); board[Y1][X1] = 0; printf("%d\n", min); } } return 0; } /* 判斷是否超出棋盤、是否已經走過 path 代表是第幾種走法 */ int valid(int board[SIZE][SIZE], int x, int y, int path) { int next_x, next_y; next_x = x + Move[path][0]; next_y = y + Move[path][1]; /* ??? */ } /* 傳入騎士現在的位置以及要尋找的是第幾步 */ void knightMove(int board[SIZE][SIZE], int x, int y, int step) { int next_x, next_y; int i; if (step >= min) { return; } for (i = 0; i < 8; ++i) { if (valid(board, x, y, i) == 1) { /* ??? */ } } }
Input
X1(1) Y1(1) X2(1) Y2(1)
X1(2) Y1(2) X2(2) Y2(2)
...
X1(N) Y1(N) X2(N) Y2(N)
註: 0 <= X1(i), Y1(i), X2(i), Y2(i) < 8 , for i=1, 2, ... , N
N為不超過20的正整數
Output
步數1
步數2
...
步數N
註: 最後須加上換行
Sample Input Download
Sample Output Download
Tags
Discuss
Description
有一座五層的數字塔,第一層有 1 個數字,第二層有 2 個數字,以此類推
整座塔呈現三角形,每個數字只和下一個距離最近的兩個數字有樓梯連結
而且只能往下走,如下圖:
1
4 6
6 9 3
6 3 7 1
2 6 3 1 8
第二層的 4 只可以走到第三層的 6、9
第二層的 6 只可以走到第三層的 9、3
從第一層開始往下走
要如何讓經過的數字加起來等於指定的值
並且經過的層數是最少的
請將層數印出
hint:
#include#define INF 2147483647 #define SIZE 5 int Value; /* 指定的數 */ int NoSolution; int min; /* 傳入即將進入第幾層、第幾個位置以及目前為止的加總 */ void goThroughTower(int tower[SIZE][SIZE], int level, int index, int sum) { if (level + 1 > min || level + 1 > SIZE) { return; } else { /* ??? */ } } int main() { int tower[SIZE][SIZE]; int i, j; while (scanf("%d", &Value) != EOF) { NoSolution = 1; min = INF; for (i = 0; i < SIZE; ++i) { for (j = 0; j <= i; ++j) scanf("%d", &tower[i][j]); } goThroughTower(tower, 0, 0, 0); if (NoSolution == 1) printf("No solution\n"); else printf("%d\n", min); } return 0; }
Input
指定的數1
塔1
...
指定的數N
塔N
註: 塔內的數以及指定的數均為 1~231-1 的正整數
N 為小於20的正整數
Output
層數1
...
層數N
註: 若無解則印 "No solution"
最後須加上換行
Sample Input Download
Sample Output Download
Tags
Discuss
Description
this is a bookbook a is thischar a[100]; fgets(a, 99, stdin); a[strlen(a)-1] = '\n';
a[strlen(a)-1] = '\n';
Input
一串字串(由小寫字母組成且長度不超過100)
Output
反轉後結果
Sample Input Download
Sample Output Download
Tags
Discuss
Description
假設有兩多項式
f(x) = A1xa1 + A2xa2 + A3xa3 + ...
g(x) = B1xb1 + B2xb2 + B3xb3 + ...
其中係數皆為整數, 次方皆為非負整數並且f的次方不重複且由小排到大, g的次方也不重複且由小排到大
則給定兩組係數序列{(A1,a1), (A2,a2), (A3,a3), ...}與{(B1,b1), (B2,b2), (B3,b3), ...}
和一整數n
求f(n) + g(n) = ?
例如
n = 12
{(3,0), (-4,3), (100,4), (-3000,65536)}與{(-12,2), (101,4), (3000,65536)}
會有
g(x) = (-12)x2 + 101x4 + 3000x65536
則
f(n) + g(n) = f(12) + g(12) = 4159299
底下是部分程式碼
#include#define MAX_TERM 100 int A[MAX_TERM], a[MAX_TERM]; int B[MAX_TERM], b[MAX_TERM]; int C[MAX_TERM], c[MAX_TERM]; int main() { int i, j, k, n, result; int f_terms, g_terms, fg_terms; scanf("%d", &f_terms); for(i = 0; i < f_terms; i++){ scanf("%d %d", &A[i], &a[i]); } scanf("%d", &g_terms); for(i = 0; i < g_terms; i++){ scanf("%d %d", &B[i], &b[i]); } scanf("%d", &n); /* ??? */ printf("%d", result); return 0; }
Input
f(x)的項數
係數 次方
g(x)的項數
係數次方
n
Output
f(n) + g(n)