summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2013-11-05 13:33:48 +0800
committerLAN-TW <lantw44@gmail.com>2013-11-05 13:33:48 +0800
commit259a2c1113be7b4998c76f6ff1298881e54746d7 (patch)
tree043418ad32efbee3e6072c425527ca2a776d0bb9
parentd0c1a2cc702018a906468218bfeef97919ad7ed4 (diff)
downloadsp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar.gz
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar.bz2
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar.lz
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar.xz
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.tar.zst
sp2013-259a2c1113be7b4998c76f6ff1298881e54746d7.zip
HW2: 找出所有可能的組合
-rw-r--r--hw2/big_judge.c27
-rw-r--r--hw2/configure.ac13
2 files changed, 36 insertions, 4 deletions
diff --git a/hw2/big_judge.c b/hw2/big_judge.c
index 1d39e81..fbb21cf 100644
--- a/hw2/big_judge.c
+++ b/hw2/big_judge.c
@@ -6,6 +6,23 @@
#include "logger.h"
#include "xwrap.h"
+#include <stdbool.h>
+#include <stdio.h>
+
+bool comb4 (Comp135* comp, int players[], int player_num) {
+ for (int i = 3; i >= 0; i--) {
+ if (players[i] + 1 <= player_num &&
+ players[i] + 1 + (3 - i) <= player_num) {
+ players[i]++;
+ for (int j = i + 1; j < 4; j++) {
+ players[j] = players[j - 1] + 1;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
int main (int argc, char* argv[]) {
if (argc < 2) {
fprintf (stderr, "Usage: %s judge_num player_num\n", argv[0]);
@@ -27,17 +44,19 @@ int main (int argc, char* argv[]) {
fprintf (stderr, "%s: `%s\' is not a number\n", argv[0], argv[2]);
return 2;
}
- if (judge_num < 4) {
+ if (player_num < 4) {
fprintf (stderr, "%s: player_num must be greater than 4\n", argv[0]);
return 3;
}
- Comp135 comp;
- comp135_init (&comp, argv[0], false);
+ Comp135 comp_struct, *comp;
+ comp = &comp_struct;
+ comp135_init (comp, argv[0], false);
+ int players[4] = {1, 2, 3, 4};
- comp135_destroy (&comp);
+ comp135_destroy (comp);
return 0;
}
diff --git a/hw2/configure.ac b/hw2/configure.ac
index 61406f0..380edd5 100644
--- a/hw2/configure.ac
+++ b/hw2/configure.ac
@@ -8,6 +8,19 @@ AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign])
AM_SILENT_RULES([yes])
+# Checks for hosts.
+AC_CANONICAL_HOST
+AC_CANONICAL_BUILD
+AH_TEMPLATE([OS_IS_LINUX])
+AH_TEMPLATE([OS_IS_FREEBSD])
+case "$host_os" in
+ *linux*)
+ AC_DEFINE([OS_IS_LINUX], [1])
+ ;;
+ *freebsd*)
+ AC_DEFINE([OS_IS_FREEBSD], [1])
+esac
+
# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C99