add the last one.

Took approx. 3 hrs to complete homework.
This commit is contained in:
juan 2021-10-25 22:46:46 +08:00
parent ca7f6301de
commit 946badf1da
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7

36
pset5/6-people.c Normal file
View file

@ -0,0 +1,36 @@
#include <math.h>
#include <stdio.h>
// 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;
}
}