mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
15 lines
359 B
C
15 lines
359 B
C
int ChickenRabbit(int *chicken, int *rabbit, int head, int foot) {
|
|
if (head < 0 || foot < 0 || foot % 2 != 0 || foot > head * 4 || foot < head * 2) {
|
|
return 0;
|
|
}
|
|
|
|
*chicken = (4 * head - foot) / 2;
|
|
*rabbit = head - *chicken;
|
|
|
|
if (*chicken < 0 || *rabbit < 0 || *chicken + *rabbit != head) {
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|