Ant book in python: page 42 coin problem


# coding: utf-8
import numpy as np

input_lines = raw_input()
data = np.array([],dtype=int)
line = ""
for i in input_lines:
    if i != " ":
        line += i
    if i == " ":
        data = np.append(data, int(line))
        line = ""
data = np.append(data, int(line))

nums = [1,5,10,50,100,500]

A = data[-1]


history = []

for i in range(len(nums)):
    history.append(np.min([data[len(nums)-i-1], A//nums[len(nums)-i-1]]))
    A -= np.min([data[len(nums)-i-1], A//nums[len(nums)-i-1]]) * nums[len(nums)-i-1]

for j in range(len(history)):
    print str(history[len(history)-j -1]),

String-> Numerical processing is a little tedious

Recommended Posts

Ant book in python: page 42 coin problem
Ant book in python: page 43 Interval scheduling
Ant book in python: page 49 Fence Repair
Ant book in python: page 45 Dictionary order minimum problem (POJ3617)
Ant book in python: page 47 Saruman's Army (POJ 3069)
Ant book in python: Sec. 2-5 Graph
Ant book in python: Priority queue self-implementation
Ant book in python: Sec. 2-4, data structures
Ant book in python: Sec.2-5 Dijkstra's algorithm
Ant book in python: Sec. 2-5 Graph (preparation)
Ant book in python: Sec. 2-3, Dynamic Programming (DP)
[Note] Project Euler in Python (Problem 1-22)
ABC166 in Python A ~ C problem
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Page cache in Python + Flask with Flask-Caching
Ant book with python (chapter3 intermediate edition ~)
Solve the maximum subarray problem in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Try to calculate a statistical problem in Python
Meta-analysis in Python
Unittest in python
The first step in the constraint satisfaction problem in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
The 18th offline real-time writing problem in Python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Create a new page in confluence with Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Use a custom error page in python / tornado
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Python reference page
Quad-tree in Python
The 19th offline real-time writing problem in Python
Reflection in Python