鸡兔同笼
程序员文章站
2022-03-10 11:46:25
一、一个笼子里关了若干只兔子和鸡(兔子有4只腿,鸡有2只腿),则笼子里面至多有多少只动物,至少有多少只动物 n = eval(input()) l = list() for k in range(n): a = int(input()) if (a%2) != 0: min = max = 0 el ......
一、一个笼子里关了若干只兔子和鸡(兔子有4只腿,鸡有2只腿),则笼子里面至多有多少只动物,至少有多少只动物
n = eval(input())
l = list()
for k in range(n):
a = int(input())
if (a%2) != 0:
min = max = 0
else:
j = int(a/4)
i = a%4
m = int(i/2)
min = m+j
max = int(a/2)
l += [(min,max)]
for b,c in l:
print(b,c,end='')
print(end='\n')
二、用户在同一行输入两个整数。代表头和脚的数量,计算笼子里有多少只鸡和兔子
head,foot = map(int,input().split())
if int(foot-head*2)/2==(foot-head*2)/2 and foot-head*2 > 0 and head>=0 and foot>=0:
print(int(head-(foot-head*2)/2), int((foot-head*2)/2))
else:
print('data error!')