Chicken and rabbit cage problem

Source: Internet
Author: User

Problem Description
A cage is closed with chickens and rabbits (chickens have 2 feet, rabbits have 4 feet, no exceptions). Known to know the total number of feet inside the cage A, ask how many animals in the cage at least how many animals?
input
Total number of feet inside the cage
Output
How many animals are there at least in the cage?
Sample input

33 10 20

Sample output

0 03 55 10

Tips

Source

#include <iostream>using namespace STD;intMain () {intNcase, Nfeet;//ncase represents the number of groups to enter test data, Nfeet indicates the number of feet entered    Cin>> ncase; for(intI=0; i<ncase; i++) {Cin>> Nfeet;if(nfeet%2!=0)//If there is an odd number of feet, the input is incorrect, because both 2 and 4 are even.{cout<<"0 0"<< Endl; }Else if(nfeet%4!=0)//To make the animal have as many as 4 feet if the number of animals is the least, to make the animal have as many as 2 feet.{cout<< nfeet/4+1<<" "<< nfeet/2<< Endl; }Else{cout<< nfeet/4<<" "<< nfeet/2<< Endl; }    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Chicken and rabbit cage problem

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.