标签:author pytho print span bsp auth python style odi
百钱买鸡:公鸡5文钱一只,母鸡3文钱一只,小鸡3只一文钱,用100文钱买100只鸡,其中公鸡,母鸡,小鸡都必须要有,问公鸡,母鸡,小鸡要买多少只刚好凑足100文钱?
思路:设定公鸡,母鸡,小鸡各买x,y,z只,则满足下列条件:
x+y+z=100;
5x+3y+z/3=100;
1 __author__ = ‘qq593‘ 2 # /usr/bin/python 3 # -*- coding:utf-8 -*- 4 5 #x is the unknown number 6 for y in range(1,33): 7 for z in range(1,98): 8 x =100-z-y 9 if (0<x<20 and x*5+y*3+z/3==100 and z%3==0): 10 print (x,y,z) 11 #z is the unknown number 12 for x in range(1, 20): 13 for y in range(1, 33): 14 z = 100 - x - y 15 if (z % 3 == 0) and (x * 5 + y * 3 + z / 3 == 100): 16 s = "gongji:%d;muji:%d;xiaoji:%d" % (x, y, z) 17 print (s) 18 #y is the unknown number 19 for x in range(1,20): 20 for z in range(98): 21 y=100-x-z 22 if (x*5+y*3+z/3==100 and z%3==0 and 0<y<33): 23 print (x,y,z)
标签:author pytho print span bsp auth python style odi
原文地址:http://www.cnblogs.com/elijahxb/p/6475493.html