struct node { int num[25]; int max; }end_node[25]; int get_max(int *fish, int left, int right) { int max = fish[left], re = left; for (int j = left + 1; j <= right; j++) { if (max < fish[j]) { max = fish[j]; re = j; } } return re; } void fishing() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) end_node[i].num[j] = 0; end_node[i].max = 0; } for (int i = 0; i < n; i++) { int ffi[25], t = 0, at = h * 60; for (int j = 0; j <= i; j++) { ffi[j] = fi[j]; at -= ti[j] * 5; } while (t < at) { int tmp = get_max(ffi, 0, i); end_node[i].num[tmp] += 5; end_node[i].max += ffi[tmp]; ffi[tmp] -= di[tmp]; if (ffi[tmp] < 0) ffi[tmp] = 0; t += 5; } } int ffi[25],max; for (int i = 0; i < n; i++) ffi[i] = end_node[i].max; max = get_max(ffi, 0, n); for (int i = 0; i < n; i++) { if (i != n - 1) printf("%d, ", end_node[max].num[i]); else printf("%d", end_node[max].num[i]); } printf("\nNumber of fish expected: %d\n\n", end_node[max].max); } int main(void) { while (scanf("%d", &n),n) { scanf("%d", &h); for (int i = 0; i < n; i++) scanf("%d", &fi[i]); for (int i = 0; i < n; i++) scanf("%d", &di[i]); for (int i = 1; i < n; i++) scanf("%d", &ti[i]); fishing(); } return 0; } /* Main.c: In function ‘fishing’: Main.c:21:22: error: ‘n’ undeclared (first use in this function) for (int i = 0; i < n; i++) ^ Main.c:21:22: note: each undeclared identifier is reported only once for each function it appears in Main.c:29:28: error: ‘h’ undeclared (first use in this function) int ffi[25], t = 0, at = h * 60; ^ Main.c:32:13: error: ‘fi’ undeclared (first use in this function) ffi[j] = fi[j]; ^ Main.c:33:10: error: ‘ti’ undeclared (first use in this function) at -= ti[j] * 5; ^ Main.c:40:16: error: ‘di’ undeclared (first use in this function) ffi[tmp] -= di[tmp]; ^ Main.c:52:4: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration] printf("%d, ", end_node[max].num[i]); ^ Main.c:52:4: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] Main.c:54:4: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] printf("%d", end_node[max].num[i]); ^ Main.c:56:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] printf("\nNumber of fish expected: %d\n\n", end_node[max].max); ^ Main.c: In function ‘main’: Main.c:60:2: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration] while (scanf("%d", &n),n) ^ Main.c:60:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [enabled by default] while (scanf("%d", &n),n) ^ Main.c:60:22: error: ‘n’ undeclared (first use in this function) while (scanf("%d", &n),n) ^ Main.c:60:24: warning: left-hand operand of comma expression has no effect [-Wunused-value] while (scanf("%d", &n),n) ^ Main.c:62:16: error: ‘h’ undeclared (first use in this function) scanf("%d", &h); ^ Main.c:64:17: error: ‘fi’ undeclared (first use in this function) scanf("%d", &fi[i]); ^ Main.c:66:17: error: ‘di’ undeclared (first use in this function) scanf("%d", &di[i]); ^ Main.c:68:17: error: ‘ti’ undeclared (first use in this function) scanf("%d", &ti[i]); ^ */ |
Double click to view unformatted code.