题目描述
一个笼子里面关了鸡和兔子(鸡有2只脚,兔子有4只脚,没有例外)。已经知道了笼子里面脚的总数a,问笼子里面至少有多少只动物,至多有多少只动物。
输入描述:
每组测试数据占1行,每行一个正整数a (a < 32768)
输出描述:
输出包含n行,每行对应一个输入,包含两个正整数,第一个是最少的动物数,第二个是最多的动物数,两个正整数用一个空格分开
如果没有满足要求的答案,则输出两个0。
示例1
输入
2
3
20
输出
0 0
5 10
题目解析:小学题
代码:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
int total;
while(cin >> total){
if(total % 2 != 0){ //奇数,不存在奇数脚动物
cout << 0 << " " << 0 << endl;
}else{
int rabbit = total / 4;
int rest = total - rabbit * 4;
int chicken = total / 2; //最多
if(rest != 0){
cout << rabbit + 1 << " " << chicken << endl;
}else{
cout << rabbit << " " << chicken << endl;
}
}
}
return 0;
}