FZU 2272 Frog 第八届福建省赛 (鸡兔同笼水题)

 Problem Description

Therearex frogs and y chicken in a garden. Kim found there are n heads and m legs in the garden. Please tell Kim how many frogs and chicken are there. (A frog has 4 legs, and a chicken has 2 legs.)

 Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: Two number n and m.

1<=n, m <=100000. The data is legal.

 Output

For each test case, output two numbers A and B – the number of frog and the number of chicken.

 Sample Input

2
2 6
2 4

 Sample Output

1 1
0 2
 
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int T;
 8     int n,m,a,b;
 9     scanf("%d",&T);
10     while(T--)
11     {
12         scanf("%d%d",&n,&m);
13         a=(m-2*n)/2;
14         b=n-a;
15         printf("%d %d
",a,b);
16     }
17     return 0;
18 }
原文地址:https://www.cnblogs.com/Annetree/p/7227425.html