题库2
P1422
print("%.3f"%c)强制输出c为3位小数
P1085
本题是一个for循环使用,有一种顺序排序法的感觉。
t = 0
a = 0
for i in range(1,8):
x,y = map(int,input().split())
h_index = x + y
if h_index > t:
t = h_index
a = i
if t > 8:
print(i)
else:
print(0)
output:
P1089***
这道题debug了很久
错误代码
own = 0
reposit = 0
c = 1
d = []
for i in range(1,13):
budget = int(input())
a = 300 + own - budget
b = a // 100
if a < 0:
c = 0
d.append(-i)
else:
if b >= 1:
reposit = reposit + b
own = a - b*100
else:
own = a
if c == 1:
print(int(reposit * 1.2 * 100 + own))
else:
print(int(d[0]))
正确代码
own = 0
reposit = 0
c = 1
d = []
for i in range(1,13):
budget = int(input())
a = 300 + own - budget
b = a // 100
if a < 0:
c = 0
d.append(-i)
else:
if b >= 1:
reposit = reposit + b
own = a - b*100
else:
own = a
if c == 1:
print(int(reposit * 120 + own))
else:
print(int(d[0]))
出现错误的测试点:
input
288
225
151
95
279
203
65
300
266
232
199
60
output_correct = 1477
output_error_code = 1476
出现错误的原因:
错误代码最后输出是deposit * 1.2 * 100 + own ; 这样算出来的话是1476.999998,输出的时候自己用的int(),而int()是向下取整。因此错误。
关键在于,为什么会出来1476.99998 这个数???
P1909
简单
循环套循环
money = 1e10
req = int(input())
for i in range(3):
pen, pr = map(int,input().split())
package = req // pen
a = req % pen
if a == 0:
b = package * pr
if money > b:
money = b
else:
b = (package+1) * pr
if money > b:
money = b
print(money)