c++8002011752 Chicken and rabbit cage

Source: Internet
Author: User

Difficulty level: A; programming language: Unlimited; run time limit: 1000ms; run space limit: 51200KB; code length limit: 2000000B
Question Description

A cage is closed with chickens and rabbits (chickens have 2 feet, rabbits have 4 feet, no exceptions). Already know the total number of feet inside the cage A, ask how many animals in the cage, at least how many animals

Input
Line 1th is the number of groups of test data n, followed by n-line input. 1 rows per set of test data, one positive integer per line (a<32768)
Output
The output contains n rows, one input per line, two positive integers, the first being the fewest number of animals, the second being the largest number of animals, and two positive integers separated by a single space
If the required answer is not met, the output is two 0.
Input example
2
3
20
Output example
0 0
5 10

From this we can see immediately, if the total number of feet is odd, then direct output 0 0, because even addition is not surprisingly number.

Next, we can judge: to make the animals at least, it is all off the rabbit (think about why?) To make the most animals, it's all off the chickens. Do you have any questions about this?

#include <iostream>using namespace Std;int a,i,x,m,n;int main () {    cin>>a;    for (i=0;i<a;i++)    {        cin>>x;        if (x%2==0)        {            m=x/4;            if (x%4!=0) n=1;            cout<<m+n<< ";            M=X/2;            cout<<m;        }        else cout<<0<< ' <<0;        cout<<endl;    }    return 0;}

  

c++8002011752 Chicken and rabbit cage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.