I have 3500 won of money, and I have to take this money and get the number of cases that I can buy at the supermarket without leaving any money behind.
The menu includes cream bread, shrimp crackers, and coke, and the prices of each menu are 500 won, 700 won, and 400 won.
However, you have to purchase at least one menu for each. I have no idea how to solve this problem.
If you can answer, it would be really helpful to understand if you could comment briefly on each line. If you reply, I'm going to use the code to correct the problem and study again.
The writing language is Python.
python algorithm
sum = 3500
a = 500
b = 700
c = 400
a_max = int(sum / a) + 1
b_max = int(sum / b) + 1
c_max = int(sum / c) + 1
for i in range(0, a_max):
for j in range(0, b_max):
for k in range(0, c_max):
tmp = i * a + j * b + k * c
if (tmp == 3500) and (i > 0) and (j > 0) and (k > 0):
print(i, j, k)
You can completely search for the number of cases.
© 2024 OneMinuteCode. All rights reserved.