鸡兔同笼

题目描述
一个笼子里面关了鸡和兔子(鸡有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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值