1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课外】14.指针2/6-1 鸡兔同笼问题.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;
}