Chicken and rabbit cage time limit: theMs | Memory Limit:65535KB Difficulty:1
-
-
Describe
-
The total number of chickens and rabbits is known to be n and the total number of legs is m. Enter n and m, output the number of chickens and rabbits in turn, and if no solution, output "no answer" (no quotation marks).
-
-
Input
-
The
-
first line enters a data A, representing the next few sets of data, in the next (a<10)
In line A, each row has an N and M. (0<m,n<100)
-
-
Output
-
-
output the number of chicken rabbits, or no answer
-
-
Sample input
-
-
214 3210 16
-
-
Sample output
-
-
2No Answer
#include <stdio.h>
int Main ()
{
int a,n,m,x;
scanf ("%d", &a);
while (a--)
{
scanf ("%d%d ", &n,&m);
int flag=0;
for (x=0;x<=n;x++)
{
Span style= "White-space:pre" > if (2*x+4* (n-x) ==m)
{
printf ("%d%d\n", x,n-x);
flag=1;
}
}
< /span>if (flag==0)
printf ("No answer\n");
}
return 0;
}
Chicken and rabbit cage