Python問題ライブラリ(コード作成)#21-24

7225 ワード

21.おつり

n, x = input("동전 종류, 합:").split()

list_n = []
count = 0

for i in range(int(n)):
    value = int(input())
    list_n.append(value)

a = reversed(list_n)

for j in a:
    count+=int(x)//j
    x=int(x)%j

print(count)

22.数独


23.水の移動

n = int(input(""))

num = 0

while n >= 3:
    if n % 5 == 0:
        num += (n//5)
        n = 0
    else:
        n -= 3
        num += 1

if 0 < n < 3:
    print("-1")
else:
    print("{0}".format(num))

24.スタック

stack = []

while True:
    a = input("명령 입력:")

    if "push" in a:
        num=int(a.split()[1])
        stack.append(num)
    
    elif "pop" in a:
        print(stack.pop())

    elif "top" in a:
        print(stack[-1])
    
    elif "bottom" in a:
        print(stack[0])
    
    else:
        break