add the last one.
Took approx. 3 hrs to complete homework.
This commit is contained in:
parent
ca7f6301de
commit
946badf1da
36
pset5/6-people.c
Normal file
36
pset5/6-people.c
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue