Chicken and Rabbit Cage
Chicken and Rabbits are in the same cage, the total heads of them is m, the total legs of them is n.
Input m and n; <=100000000;
Output the number of chicken and rabbit.
If the number isn't right , output "You count wrong!"
Input
input two integers m and n;
Output
two integers:the number of chicken and rabbits.
Sample Input
14 32
Sample Output
12 2
代码:
#include <stdio.h>
int main(){
int m,n,chi,rab;
scanf("%d %d", &m , &n);
if(n % 2 !=0 || n <= 2m || n >= 4m){
printf("You count wrong!");
return 0;
}
for(chi = 1; chi <= m; chi++){
for(rab = 1;rab <= m;rab++){
if(2*chi + 4 * rab == n && chi + rab == m){
printf("%d %d",chi,rab);
break;
}
}
}
return 0;
}为什么我这个提交上去显示答案错误