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