From 259a2c1113be7b4998c76f6ff1298881e54746d7 Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Tue, 5 Nov 2013 13:33:48 +0800 Subject: =?UTF-8?q?HW2:=20=E6=89=BE=E5=87=BA=E6=89=80=E6=9C=89=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E7=B5=84=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw2/big_judge.c | 27 +++++++++++++++++++++++---- hw2/configure.ac | 13 +++++++++++++ 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 +#include + +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 -- cgit v1.2.3