[C language] people working cat problem

And the total number of cats known as n, the total number of legs is m. N inputs and m, the number of the output sequence number of human and cat (note that there are two human legs, cats have four legs, without considering other cases).

If no solution (obtained solution is not consistent with common sense), the output "No answer" (without quotes).

#include <stdio.h>
int main()
{
 int a,b,n,m;
 scanf("%d %d",&n,&m);
 a=2*n-m/2;
 b=n-a;
 if(a>=0 && b>=0 && m%2==0)
 printf("%d %d\n",a,b);
 else
 printf("No answer\n");
 return 0;
}

[Foundation: the need to represent the unknown quantity with a known quantity, rather than using unknowns to express an unknown quantity. ]

Guess you like

Origin www.cnblogs.com/asher0608/p/11689436.html