Title Address: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=64?
Description
The total number of chickens and rabbits is known to beN,the total number of legs ism. InputNand them,output the number of chickens and rabbits in turn, and if there is no solution, the output"No Answer" (No quotes).
input
The first line enters a dataA,The next few sets of data are represented in the next(A<10)
Aline, each row has aNand theM. (0<m,n<100)
Output
output the number of chicken rabbits, orNo Answer
Sample Input
2
14 32
10 16
Sample Output
12 2
No Answer?? Code: #include <stdio.h>
Output results
N-Number and, M-leg number and
static void Printresult (int n,int m);
int main ()
{
???? int readlen = 0;
???? scanf ("%d", &readlen);
???? GetChar ();
????
???? while (Readlen > 0)
???? {
????????? int n = 0;
????????? int m = 0;
?????????
????????? scanf ("%d%d", &n,&m);
????????? GetChar ();
?????????
????????? Printresult (N,M);
?????????
????????? --readlen;
???? }
????
???? return 0;
}
Output results
N-Number and, M-leg number and
static void Printresult (int n,int m) {??? if (M<n)??? {????? printf ("No answer");????????? return;???}????? int T Mpvalue = M-2*n;
???? if (Tmpvalue < 0 | | tmpvalue% 2! = 0)
???? {
????????? printf ("No answer");
????????? Return
???? }
????
???? int rabbitcount = TMPVALUE/2;???? int chickencount = N-rabbitcount;?? ? if (Chickencount < 0)?? {?????. printf ("No answer");????????? return;??}????
???? printf ("%d%d\n", chickencount,rabbitcount);
}?? Judging by the number of equations the rabbit: (m-2n)/2 chicken: N-Rabbit number? In addition, the code of his own writing is too cumbersome to judge the conditions, the recommended excellent program is as follows:? #include <iostream>using namespace Std;int Main () {int N,a,b,p,q;cin>>n;while (n--) {cin>>a>>b;q= (b-2*a)/2;p=a-q;if (p<0 | | q<0 | | b%2) cout<< "No answer" <<endl;else cout<<p<< "" <<q<<endl;}?
18-language Introduction -18-chicken rabbit with Cage