16:买房子
【题目名称】买房子 【题目来源】http://noi.openjudge.cn/ch0105/16/ Author: 潘磊 just_panleijust.edu.cn Version: 1.0 # 自定义函数defyear_for_buying_house(salary:int,price:int,rate:int,year:int)-int: 返回在指定年薪、房价、房价增长率、年限条件下程序员买得起房的年份。 Args: salary (int): 指定年薪 price (int): 指定房价 rate (int): 指定房价增长率 year (int): 指定年限 Returns: int: 程序员买得起房的年份如果year年内始终买不起则为-1 savingssalary# 当前积蓄初始为指定年薪salaryhome_priceprice# 当前房价初始为指定房价pricegrowth_rate1rate/100# 房价年递增倍数foriinrange(1,year1):# 从第一年依次循环到第year年ifsavingshome_price:# 如果当前积蓄savings大于等于当前房价home_pricereturni# 说明当前年份买得起房返回当前年份savingssalary# 增加积蓄home_price*growth_rate# 房价上涨return-1# 指定year年限内始终买不起房返回-1defmain():N,Kmap(int,input().split())ansyear_for_buying_house(N,200,K,20)print(ansifans!-1elseImpossible,end)if__name____main__:main()