Problem:


 おつり 

問題

太郎君はよくJOI雑貨店で買い物をする． JOI雑貨店には硬貨は500円，100円，50円，10円，5円，1円が十分な数だけあり，いつも最も枚数が少なくなるようなおつりの支払い方をする．太郎君がJOI雑貨店で買い物をしてレジで1000円札を1枚出した時，もらうおつりに含まれる硬貨の枚数を求めるプログラムを作成せよ．

例えば入力例1の場合は下の図に示すように，4を出力しなければならない． 

入力

入力は複数のデータセットからなる．各データセットは1行からなり，太郎君が支払う金額（1以上1000未満の整数）が1つだけ書かれている．入力データはゼロ１つの行で終了する．

データセットの数は 5 を超えない．

出力

データセットごとにおつりに含まれる硬貨の枚数を1行に出力せよ．

入出力例

入力例

380
1
0

出力例

4
15

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
380
1
0


Sample output:
4
15

Submission status: Wrong Answer

Solution code:
def otsuri(x):
    a=0
    y=1000-x
    while y>=0:
        if y-500<0:
            break
        else:
            y=y-500
            a=a+1
    while y>=0:
        if y-100<0:
            break
        else:
            y=y-100
            a=a+1
    while y>=0:
        if y-50<0:
            break
        else:
            y=y-50
            a=a+1
    while y>=0:
        if y-10<0:
            break
        else:
            y=y-10
            a=a+1
    while y>=0:
        if y-5<0:
            break
        else:
            y=y-5
            a=a+1
    while y>=0:
        if y-1<0:
            break
        else:
            y=y-1
            a=a+1
    print a

Submission status: Wrong Answer

Solution code:
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        print
    else:

         while y>=0:
            if y-500<0:
                break
            else:
                y=y-500
                a=a+1
         while y>=0:
            if y-100<0:
                break
            else:
                y=y-100
                a=a+1
         while y>=0:
            if y-50<0:
                break
            else:
                y=y-50
                a=a+1
         while y>=0:
            if y-10<0:
                break
            else:
                y=y-10
                a=a+1
         while y>=0:
            if y-5<0:
                break
            else:
                y=y-5
                a=a+1
         while y>=0:
            if y-1<0:
                break
            else:
                y=y-1
                a=a+1
         print a

Submission status: Wrong Answer

Solution code:
import sys
x=int(sys.stdin.readline())
        
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        print
    else:

         while y>=0:
            if y-500<0:
                break
            else:
                y=y-500
                a=a+1
         while y>=0:
            if y-100<0:
                break
            else:
                y=y-100
                a=a+1
         while y>=0:
            if y-50<0:
                break
            else:
                y=y-50
                a=a+1
         while y>=0:
            if y-10<0:
                break
            else:
                y=y-10
                a=a+1
         while y>=0:
            if y-5<0:
                break
            else:
                y=y-5
                a=a+1
         while y>=0:
            if y-1<0:
                break
            else:
                y=y-1
                a=a+1
         print a
y=otsuri(x)
print y

Submission status: Wrong Answer

Solution code:
import sys
x=int(sys.stdin.readline())
        
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        print
    else:

         while y>=0:
            if y-500<0:
                break
            else:
                y=y-500
                a=a+1
         while y>=0:
            if y-100<0:
                break
            else:
                y=y-100
                a=a+1
         while y>=0:
            if y-50<0:
                break
            else:
                y=y-50
                a=a+1
         while y>=0:
            if y-10<0:
                break
            else:
                y=y-10
                a=a+1
         while y>=0:
            if y-5<0:
                break
            else:
                y=y-5
                a=a+1
         while y>=0:
            if y-1<0:
                break
            else:
                y=y-1
                a=a+1
         return a

print otsuri(x)

Submission status: Wrong Answer

Solution code:
import sys
x=sys.stdin.read().split()
        
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        return 0
    else:

         while y>=0:
            if y-500<0:
                break
            else:
                y=y-500
                a=a+1
         while y>=0:
            if y-100<0:
                break
            else:
                y=y-100
                a=a+1
         while y>=0:
            if y-50<0:
                break
            else:
                y=y-50
                a=a+1
         while y>=0:
            if y-10<0:
                break
            else:
                y=y-10
                a=a+1
         while y>=0:
            if y-5<0:
                break
            else:
                y=y-5
                a=a+1
         while y>=0:
            if y-1<0:
                break
            else:
                y=y-1
                a=a+1
         return a

x=map(int,x)
for change in x:
    print otsuri(change)

Submission status: Wrong Answer

Solution code:
pay = int(raw_input())
change = 1000 - pay
coin = [1, 5, 10, 50, 100, 500]
n_coin = [0, 0, 0, 0, 0, 0]
success = 0

if (change > coin[5]):
    change -= coin[5]
    n_coin[5] = 1
    for i4 in range(5):
        for i3 in range(2):
            for i2 in range(5):
                for i1 in range(2):
                    for i0 in range(5):
                        if (change == coin[4] * i4 + coin[3] * i3 + coin[2] * i2 + coin[1] * i1  + coin[0] * i0):
                            success = 1
                            break;
                    if (success):break;
                if (success):break;
            if (success):break;
        if (success):break;
    n_coin[4] = i4
    n_coin[3] = i3
    n_coin[2] = i2
    n_coin[1] = i1   
    n_coin[0] = i0

    su = 0
    for i in range(6):
        su += n_coin[i]
else:
    for i4 in range(5):
        for i3 in range(2):
            for i2 in range(5):
                for i1 in range(2):
                    for i0 in range(5):
                        if (change == coin[4] * i4 + coin[3] * i3 + coin[2] * i2 + coin[1] * i1  + coin[0] * i0):
                            success = 1
                            break;
                    if (success):break;
                if (success):break;
            if (success):break;
        if (success):break;
    n_coin[4] = i4
    n_coin[3] = i3
    n_coin[2] = i2
    n_coin[1] = i1   
    n_coin[0] = i0

    su = 0
    for i in range(6):
        su += n_coin[i]

print su

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
#coding:utf-8

coin = [500,100,50,10,5,1]
oturi = 1000 - int(input())
ret = 0
for c in coin:
    ret += oturi // c
    oturi %= c
print(ret)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

x = 1000 - int(input())

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

ret = 0
for coin in coins:
    n = x//coin
    x = x - n*coin
    ret += n

print(ret)

Submission status: Wrong Answer

Solution code:
c, o= 0, 1000-int(input())
if o>= 500:
    o, c= o-500, c+1
if o>= 100:
    t= o//100
    o, c= o-(100*t), c+t
if o>= 10:
    t= o//10
    o, c= o-(10*t), c+t
if o>= 5:
    t= o//5
    o, c= o-(5*t), c+t
print(c)

Submission status: Wrong Answer

Solution code:
c, o= 0, 1000-int(input())
def change(v):
    global c, o
    if o>= v: 
        t= o//v
        o, c= o-(v*t), c+t

for l in [500, 100, 50, 10, 5, 1]: change(l)
print(c+o)

Submission status: Wrong Answer

Solution code:
c, o= 0, 1000-int(input())
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

for l in [500, 100, 50, 10, 5, 1]: change(l)
print(int(c+o))

Submission status: Wrong Answer

Solution code:
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    p = int(input())
    ch = 1000 - p

    count = 0
    for coin in coins:
        n = ch // coin
        ch -= coin * n
        count += n
    
    print(count)

Submission status: Wrong Answer

Solution code:
taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]
print(changes)
for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)

Submission status: Wrong Answer

Solution code:
COINS = [500, 100, 50, 10, 5, 1]

change = 1000 - int(input())
total = 0
for coin in COINS:
    total += change // coin
    change %= coin

print(total)

Submission status: Wrong Answer

Solution code:
for e in iter(input,'0'):
 a,b=0,1000-int(e)
 for i in[500,100,50,10,5]:
  b%=i
  a+=b//i
 print(b+a)

Submission status: Wrong Answer

Solution code:
coin = [500, 100, 50, 10, 5, 1]; ans = 0;
rest = 1000-int(raw_input())
for i in range(6):
    while(rest>=coin[i]):
        rest-=coin[i]; ans+=1;
print(str(ans))

Submission status: Wrong Answer

Solution code:
c = [500,100,50,10,5,1]
while True:
    e = int(raw_input())
    if e == 0: break
    i,m = 0,0
    while e > 0:
        if e >= c[i]:
            e -= c[i]
            m += 1
        else:
            i += 1
    print m

Submission status: Accepted

Solution code:
while True:
    n, ans = 1000 - int(input()), 0
    if n == 1000:
        break
    for m in (500, 100, 50, 10, 5, 1):
        ans, n = ans+n//m, n%m
    print(ans)

Submission status: Accepted

Solution code:
coin = [500, 100, 50, 10, 5, 1]

def change( price ):
    result = 0
    for c in coin:
        result += price/c
        price -= price/c*c
    return result

while True:
    p = int(raw_input())
    if p == 0: break
    print change( 1000 - p )

Submission status: Accepted

Solution code:
import sys
x=sys.stdin.read().split()
        
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        sys.exit(0)
    else:

         while y>=0:
            if y-500<0:
                break
            else:
                y=y-500
                a=a+1
         while y>=0:
            if y-100<0:
                break
            else:
                y=y-100
                a=a+1
         while y>=0:
            if y-50<0:
                break
            else:
                y=y-50
                a=a+1
         while y>=0:
            if y-10<0:
                break
            else:
                y=y-10
                a=a+1
         while y>=0:
            if y-5<0:
                break
            else:
                y=y-5
                a=a+1
         while y>=0:
            if y-1<0:
                break
            else:
                y=y-1
                a=a+1
         return a

x=map(int,x)
for change in x:
    print otsuri(change)

Submission status: Accepted

Solution code:
while 1:
    pay = int(raw_input())
    if (pay == 0):
        break;
    change = 1000 - pay
    coin = [1, 5, 10, 50, 100, 500]
    n_coin = [0, 0, 0, 0, 0, 0]
    success = 0

    if (change > coin[5]):
        change -= coin[5]
        n_coin[5] = 1
        for i4 in range(5):
            for i3 in range(2):
                for i2 in range(5):
                    for i1 in range(2):
                        for i0 in range(5):
                            if (change == coin[4] * i4 + coin[3] * i3 + coin[2] * i2 + coin[1] * i1  + coin[0] * i0):
                                success = 1
                                break;
                        if (success):break;
                    if (success):break;
                if (success):break;
            if (success):break;
        n_coin[4] = i4
        n_coin[3] = i3
        n_coin[2] = i2
        n_coin[1] = i1   
        n_coin[0] = i0
    
        su = 0
        for i in range(6):
            su += n_coin[i]
    else:
        for i4 in range(5):
            for i3 in range(2):
                for i2 in range(5):
                    for i1 in range(2):
                        for i0 in range(5):
                            if (change == coin[4] * i4 + coin[3] * i3 + coin[2] * i2 + coin[1] * i1  + coin[0] * i0):
                                success = 1
                                break;
                        if (success):break;
                    if (success):break;
                if (success):break;
            if (success):break;
        n_coin[4] = i4
        n_coin[3] = i3
        n_coin[2] = i2
        n_coin[1] = i1   
        n_coin[0] = i0
    
        su = 0
        for i in range(6):
            su += n_coin[i]
    print su

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#coding:utf-8

while True:
    coin = [500,100,50,10,5,1]
    oturi = 1000 - int(input())
    if oturi == 1000:
        break
    ret = 0
    for c in coin:
        ret += oturi // c
        oturi %= c
    print(ret)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

while True:
    x = 1000 - int(input())
    if x == 1000:
        break

    ret = 0
    for coin in coins:
        n = x//coin
        x = x - n*coin
        ret += n

    print(ret)

Submission status: Accepted

Solution code:
while 1:
    n = 1000 - input()
    if n==1000:break
    m = [500,100,50,10,5,1]
    for i in range(6):
        x = n / m[i]; n -= m[i] * x; m[i] = x;
    print reduce(lambda a, x: a+x, m)

Submission status: Accepted

Solution code:
while 1:
    n = 1000-input()
    if n==1000:break
    m = [500,100,50,10,5,1]
    for i in range(6):
        m[i],n = divmod(n,m[i])
    print reduce(lambda a, x: a+x, m)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve(price):
    change = 1000 - price
    total_coins = 0
    for coin in [500, 100, 50, 10, 5, 1]:
        coins, change = divmod(change, coin)
        total_coins += coins
    return total_coins


if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        else:
            print(solve(n))

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if m == 0:break
    n = 1000 - m
    a = n // 500
    n%=500
    b = n // 100
    n%=100
    c = n // 50
    n%=50
    d = n // 10
    n%=10
    e = n // 5
    n%=5
    print(a + b + c + d + e + n)

Submission status: Accepted

Solution code:
while True:
    m = int(input())
    if m == 0:break
    coin = [500,100,50,10,5,1]
    m = 1000 - m
    ans = 0
    for c in coin:
        ans+=m // c
        m%=c
    print(ans)

Submission status: Accepted

Solution code:
import sys

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

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    c = [ i for i in range(n+1) ]
    for i in range(len(coins)):
        coin = coins[i]
        if coin <= n:
            c[coin] = 1
            coins.append(coin)

    for coin in coins:
        for p in range(coin+1, n+1):
            minc = c[p]
            if minc == 1:
                continue
            c[p] = c[p-coin]+1 if minc > c[p-coin] + 1 else minc

    print(c[n])

Submission status: Accepted

Solution code:
import sys

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

for i in sys.stdin:
    if int(i) == 0:
        break

    n =1000-int(i)
    cnt = 0

    while n != 0:
        for i in range(len(coins)):
            if n >= coins[i]:
                n = n-coins[i]
                break
        cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
coins = (500, 100, 50, 10, 5, 1)
while True:
    n = int(input())
    if not n:
        break
    m, c = 0, 1000 - n
    for coin in coins:
        mt, c = divmod(c, coin)
        m += mt
        if not c:
            break
    print(m)

Submission status: Accepted

Solution code:
a=(500,100,50,10,5)
while 1:
    b,c=1000-int(input()),0
    if b==1000:break
    for i in a:
        d,b=divmod(b,i)
        c+=d
    print(b+c)

Submission status: Accepted

Solution code:
def change(v):
    global c, o
    if o>= v:
        t= o//v
        o, c= o-(v*t), c+t

while True:
    o= int(input())
    if o== 0: break
    c, o= 0, 1000-o
    for l in [500, 100, 50, 10, 5, 1]: change(l)
    print(c+o)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n==0: break

    ans = 0
    while(n<=500):
        n += 500
        ans += 1
    while(n<=900):
        n += 100
        ans += 1
    while(n<=950):
        n += 50
        ans += 1
    while(n<=990):
        n += 10
        ans += 1
    while(n<=995):
        n += 5
        ans += 1
    while(n<=999):
        n += 1
        ans += 1

    print(ans)

Submission status: Accepted

Solution code:
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    while True:
        p = int(input())
        if p == 0:
            break
        ch = 1000 - p

        count = 0
        for coin in coins:
            n = ch // coin
            ch -= coin * n
            count += n
        
        print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

"""
import sys
from sys import stdin
input = stdin.readline


def count_coint(change):
    ans = 0
    coins = (500, 100, 50, 10, 5, 1)
    for c in coins:
        t = change // c
        ans += t
        change -= t * c
    return ans


def main(args):
    while True:
        payment = int(input())
        if payment == 0:
            break

        change = 1000 - payment
        result = count_coint(change)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
coin=[500,100,50,10,5]
while True:
    n=1000-int(input())
    if n==1000:break
    count=0
    for c in coin:
        count+=n//c
        n=n%c
    print(count+n)

Submission status: Accepted

Solution code:
taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]

for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)

Submission status: Accepted

Solution code:
COINS = [500, 100, 50, 10, 5, 1]

change = 1000 - int(input())
while change != 1000:
    total = 0
    for coin in COINS:
        total += change // coin
        change %= coin

    print(total)

    change = 1000 - int(input())

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    ans = 0
    change = 1000 - N
    while change >= 500:
        change -= 500
        ans += 1
    while change >= 100:
        change -= 100
        ans += 1
    while change >= 50:
        change -= 50
        ans += 1
    while change >= 10:
        change -= 10
        ans += 1
    while change >= 5:
        change -= 5
        ans += 1
    ans += change
    print(ans)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n: break
  ans = 0
  m = 1000 - n
  for i in [500,100,50,10,5,1]:
    ans += m // i
    m = m % i
  print(ans)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 b,c=1000-int(e),0
 for i in[500,100,50,10,5]:
  d,b=divmod(b,i)
  c+=d
 print(b+c)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 b,c=1000-int(e),0
 for i in[500,100,50,10,5]:
  d,b=b//i,b%i
  c+=d
 print(b+c)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a,b=0,1000-int(e)
 for i in[500,100,50,10,5]:
  d,b=b//i,b%i
  a+=d
 print(b+a)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a,b=0,1000-int(e)
 for i in[500,100,50,10,5]:
  a+=b//i
  b%=i
 print(b+a)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
 a,b=0,1000-int(e)
 for i in[500,100,50,10,5]:
  a+=b//i
  b%=i
 print(a+b)

Submission status: Accepted

Solution code:
# AOJ 0521: Change
# Python3 2018.6.30 bal4u

c = [500, 100, 50, 10, 5, 1]
while True:
	m = 1000-int(input())
	if m == 1000: break
	ans = 0
	for i in c:
		ans += m // i
		m %= i 
	print(ans)

Submission status: Accepted

Solution code:
while True:
  c =0
  a = int(input())
  if a == 0:break
  else:
    me = 1000 -a
    while me != 0:
     if me >= 500:
        me -= 500 
        c +=1 
     elif me >= 100:
        me -= 100 
        c +=1
     elif me >= 50:
        me -= 50
        c+=1
     elif me >= 10:
        me -= 10
        c +=1
     elif me >= 5:
        me -= 5
        c +=1
     elif me >= 1:
        me -= 1
        c+=1
       
       
     
     
    print c

Submission status: Accepted

Solution code:
def mapAccumL(f, acc, x):
  ret = []
  for xx in x:
    tmp = f(acc, xx)
    ret.append(tmp[1])
    acc = tmp[0]
  return (acc, ret)

def calc(s, x):
  n = s / x
  return (s - n * x, n)

while True:
  n = input()

  if not n:
    break

  print sum(mapAccumL(calc, 1000 - n,
                      [500, 100, 50, 10, 5, 1])[1])

Submission status: Accepted

Solution code:
while 1:
    n = int(raw_input())
    if n == 0:
        break
    r = 0
    m = 1000 - n
    for c in [500, 100, 50, 10, 5, 1]:
        d, m = divmod(m, c)
        r += d
    print r

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    L=[500,100,50,10,5,1]
    temp=1000-n
    cnt=0
    for i in L:
        j=0
        while i*j<=temp:
	    j+=1
        temp-=i*(j-1)
        cnt+=(j-1)
    print cnt

Submission status: Accepted

Solution code:
import sys

#fp = open("input.txt", "r")
fp = sys.stdin

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    change = 1000 - n
    count = 0

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

    for c in coin:
        count += change / c
        change = change - (change / c) * c

    print count

Submission status: Accepted

Solution code:
p = (500, 100, 50, 10, 5, 1)
while True:
    n = int(raw_input())
    if n == 0:
        break
    n = 1000 - n
    r = 0
    while n != 0:
        n -= [i for i in p if i <= n][0]
        r += 1
    print r

Submission status: Accepted

Solution code:
coin = [500, 100, 50, 10, 5, 1];
while(1):
    ipt = int(raw_input())
    if ipt==0: break
    ans = 0; rest = 1000-ipt;
    for i in range(6):
        while(rest>=coin[i]):
            rest-=coin[i]; ans+=1;
    print(str(ans))

Submission status: Accepted

Solution code:
coins = (500, 100, 50, 10, 5, 1)

def count(x, y):
    ret = 0
    while x >= y:
        x -= y
        ret += 1
    return x, ret

while True:
    n = input()
    if n == 0:
        break
    ans = 0
    n = 1000 - n
    for val in coins:
        n,  t = count(n, val)
        ans += t

    print(ans)

Submission status: Accepted

Solution code:
c = [500,100,50,10,5,1]
while True:
    e = int(raw_input())
    if e == 0: break
    e = 1000-e
    i,m = 0,0
    while e > 0:
        if e >= c[i]:
            e -= c[i]
            m += 1
        else:
            i += 1
    print m

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n: break
  a = 0
  m = 1000 - n
  for i in [500,100,50,10,5,1]:
    a += m // i
    m = m % i
  print(a)

Submission status: Accepted

Solution code:
for e in iter(input,'0'):
	a,b=0,1000-int(e)
	for i in[500,100,50,10,5]:
		a+=b//i
		b%=i
	print(a+b)

Submission status: Accepted

Solution code:
a=[500,100,50,10,5,1]
while True:
    n=int(input())
    if n==0:
        break
    n=1000-n
    sum=0
    for i in a:
        sum +=n//i
        n %=i
    print(sum)

Submission status: Accepted

Solution code:

while True:
    n = int(input())
    if n == 0:
        break
    p = 1000-n
    
    c = 0
    for k in [500, 100, 50, 10, 5, 1]:
        if p == 0:
            break
        c += p // k
        p %= k
        
    print(c)

Submission status: Accepted

Solution code:
for i in range(1,5+1) :
    n = int(input())
    x = 1000-n
    if n == 0 :
        break
    
    else :
        a = x//500
        b = (x-500*a)//100
        c = (x-500*a-100*b)//50
        d = (x-500*a-100*b-50*c)//10
        e = (x-500*a-100*b-50*c-10*d)//5
        f = x-500*a-100*b-50*c-10*d-5*e
        print(a+b+c+d+e+f)

Submission status: Accepted

Solution code:
c = [500, 100, 50, 10, 5, 1]
while True:
	m = 1000-int(input())
	if m == 1000: break
	ans = 0
	for i in c:
		ans += m // i
		m %= i 
	print(ans)

Submission status: Accepted

Solution code:
coin = [500,100,50,10,5,1]
while True:
    n = int(input())
    if n == 0:
        break
    n = 1000-n
    ans = 0
    for c in coin:
        ans += n//c
        n %= c
    print(ans)

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if a == 0:break

    A = [500,100,50,10,5,1]
    a= 1000 - a
    ans = 0
    for b in A:
        ans+=a // b
        a%=b
    print(ans)

Submission status: Accepted

Solution code:
def cash_co(change):
    ans = 0
    a = (500, 100, 50, 10, 5, 1)
    for i in a:
        co = change // i
        ans += co
        change = change - i * co
    return ans
        

while True:
    n = int(input())
    if n == 0:
        break
        
    change = 1000 - n
    result = cash_co(change)
    print(result)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    i = 0
    a=1000-n
    if a>=500:
        a = a-500
        i =i+1
    if a>=100:
        b = a//100
        i = i+b
        a = a-(100*b)
    if a>=50:
        i = i+1
        a = a-50
    if a>=10:
        b = a//10
        i = i+b
        a = a-(10*b)
    if a>=5:
        i = i+1
        a = a-5
    i = i+a
    print(i)

Submission status: Accepted

Solution code:
while True:
    a=int(input())
    if a==0:
        break
    b=((1000-a)//500)
    c=(((1000-a)-500*b)//100)
    d=(((1000-a)-500*b-100*c)//50)
    e=(((1000-a)-500*b-100*c-50*d)//10)
    f=(((1000-a)-500*b-100*c-50*d-10*e)//5)
    g=((1000-a)-500*b-100*c-50*d-10*e-5*f)
    print(b+c+d+e+f+g)

Submission status: Accepted

Solution code:
coin = [500,100,50,10,5,1]
while True:
    n = int(input())
    if n == 0:
        break
    n = 1000-n
    ans = 0
    for c in coin:
        ans += n//c
        n %= c
    print(ans)

Submission status: Accepted

Solution code:
a,b = 1,0
while a > 0:
    a=int(input())
    if a == 0:
        break
    b = 1000 - a
    c = b // 500
    d = b % 500 // 100
    e = b % 100 // 50
    f = b % 50 // 10
    g = b % 10 // 5
    h = b % 5
    print(c + d + e + f + g + h)

Submission status: Accepted

Solution code:
while True:
    m=int(input())
    p=1000-m
    y500=p//500
    x500=p%500
    y100=x500//100
    x100=x500%100
    y50=x100//50
    x50=x100%50
    y10=x50//10
    x10=x50%10
    y5=x10//5
    x5=x10%5
    
    if m==0:
        break
    
    print(y500+y100+y50+y10+y5+x5)

Submission status: Accepted

Solution code:
while True:
    x = int(input())
    if x == 0:
        break
    else:
        x=1000-x
        a=x//500
        b=(x-500*a)//100
        c=(x-(500*a+100*b))//50
        d=(x-(500*a+100*b+50*c))//10
        e=(x-(500*a+100*b+50*c+10*d))//5
        f=(x-(500*a+100*b+50*c+10*d+5*e))//1
        print(a+b+c+d+e+f)

Submission status: Accepted

Solution code:
while True:
    price = int(input())
    change = 1000 - price
    n = 0
    if price == 0:
        break
    if change >= 500:
        change -= 500
        n += 1
    while change >= 100:
        change -= 100
        n += 1
    if change >= 50:
        change -= 50
        n += 1
    while change >= 10:
        change -= 10
        n += 1
    if change >= 5:
        change -= 5
        n += 1
    while change >= 1:
        change -= 1
        n += 1
        
    print(n)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
while True:
    n=int(input())
    if 0<=n<1000:
        if n==0:
            break
        else:
            sum=0
            
            sum+=(1000-n)//500
            sum+=(1000-n)%500//100
            sum+=(1000-n)%500%100//50
            sum+=(1000-n)%500%100%50//10
            sum+=(1000-n)%500%100%50%10//5
            sum+=(1000-n)%500%100%50%10%5//1
            
    print(sum)

Submission status: Accepted

Solution code:
while True:
    price = int(input())
    change = 1000 - price
    n = 0

    if price == 0:
        break

    if change >= 500:
        change -= 500
        n += 1
    while change >= 100:
        change -= 100
        n += 1
    if change >= 50:
        change -= 50
        n += 1
    while change >= 10:
        change -= 10
        n += 1
    if change >= 5:
        change -= 5
        n += 1
    while change >= 1:
        change -= 1
        n += 1
    
    print(n)

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:
        break
    m=1000-n
    a=0
    for i in [500,100,50,10,5,1]:
        a+=m//i
        m=m%i
    print(a)

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if  a == 0:
        break
    else:
        b = 1000-a
        c = b%500
        d = c%100
        e = d%50
        f = e%10
        g = f%5
        print(b//500+c//100+d//50+e//10+f//5+g)

Submission status: Accepted

Solution code:
i=1
while True:
    x=int(input())
    if x==0:
        break
    x=1000-x
    a=x//500
    b=(x%500)//100
    c=(x%100)//50
    d=(x%50)//10
    e=(x%10)//5
    f=x%5
    print(a+b+c+d+e+f)
    i+=1

Submission status: Accepted

Solution code:
c = [500, 100, 50, 10, 5, 1]
while True:
	m = 1000-int(input())
	if m == 1000: break
	ans = 0
	for i in c:
		ans += m // i
		m %= i 
	print(ans)

Submission status: Accepted

Solution code:
while True:
    x=int(input())
    if x==0:
        break
    a=1000-x
    b=a//500
    c=a%500
    d=c//100
    e=c%100
    f=e//50
    g=e%50
    h=g//10
    i=g%10
    j=i//5
    k=i%5
    print(b+d+f+h+j+k)

Submission status: Accepted

Solution code:
for i in range(5):
    a=int(input())
    if a == 0:
        break
    b=1000-a
    if b > 500:
        c=b-(500*(b//500))
        d=c-(100*(c//100))
        e=d-(50*(d//50))
        f=e-(10*(e//10))
        g=f-(5*(f//5))
        print((b//500)+(c//100)+(d//50)+(e//10)+(f//5)+g)
    elif b > 100:
        g=b-(100*(b//100))
        h=g-(50*(g//50))
        i=h-(10*(h//10))
        j=i-(5*(i//5))
        print((b//100)+(g//50)+(h//10)+(i//5)+(j))
    elif b > 50:
        k=b-(50*(b//50))
        l=k-(10*(k//10))
        m=l-(5*(l//5))
        print((b//50)+(k//10)+(l//5)+(m))
    elif b > 10:
        n=b-(10*(b//10))
        o=n-(5*(n//5))
        print((b//10)+(n//5)+(o))
    elif b > 5:
        p=b-(5*(b//5))
        print((b//5)+(p))
    else:
        print(b)