From 946badf1dad0f98b0c24f9451b4ea742611bb087 Mon Sep 17 00:00:00 2001 From: juan Date: Mon, 25 Oct 2021 22:46:46 +0800 Subject: [PATCH] add the last one. Took approx. 3 hrs to complete homework. --- pset5/6-people.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pset5/6-people.c diff --git a/pset5/6-people.c b/pset5/6-people.c new file mode 100644 index 0000000..e9d6bab --- /dev/null +++ b/pset5/6-people.c @@ -0,0 +1,36 @@ +#include +#include + +// Function prototype +int checkf(float f); + +int main(void) { + // Initialize variables + int m, n; + int b, c; // a -> 1, b -> 2 etc. + float a, d; // a -> 1, b -> 2 etc. + scanf("%i%i", &m, &n); + + // Start brute forcing + for (b = 0; b <= n; b++) { + for (c = 0; c <= n; c++) { + d = (float)(n - m - b - c * 2) / 3; + if (checkf(d)) { + a = (float)(2 * m - n + c + d * 2); + if (checkf(a)) { + printf("%i %i %i\n", b, c, (int)d); + } + } + } + } + + return 0; +} + +int checkf(float f) { + if (floorf(f) == f && f >= 0) { + return 1; + } else { + return 0; + } +}