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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    N=int(input())
    k=1000-N
    f=int(k/500)
    h=int((k%500)/100)
    i=int(((k%500)%100)/50)
    t=int((((k%500)%100)%50)/10)
    v=int(((((k%500)%100)%50)%10)/5)
    o=int((((((k%500)%100)%50)%10)%5)/1)

    if N==0:
        break
    print(f+h+i+t+v+o)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    try:
        a=list(map(int,input().split()))
        x=0
        y=0
        z=0
        u=0
        w=0
        
        g=1000-a[0]
        if g==1000:
            pass
        else:
            if g>=500:
                x=1
                g=g-500
            y=g//100
            g=g-100*y
            if g>=50:
                z=1
                g=g-50
            u=g//10
            g=g-10*u
            if g>=5:
                w=1
                g=g-5
            print(x+y+z+u+w+g)
    except:
        break;

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = 0

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

Submission status: Accepted

Solution code:
i = 0
while i < 5:
    fee = int(input())
    if fee == 0:
        break
    
    refee = 1000 - fee
    
    C500 = refee     // 500
    C100 = refee%500 // 100
    C50  = refee%100 // 50
    C10  = refee%50  // 10
    C5   = refee%10  // 5
    C1   = refee%5
    
    sum = C500 + C100 + C50 + C10 + C5 + C1
    print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    m1=y//500
    m2=(y-(500*m1))//100
    m3=((y-(500*m1))-(100*m2))//50
    m4=(((y-(500*m1))-(100*m2))-(50*m3))//10
    m5=((((y-(500*m1))-(100*m2))-(50*m3))-(10*m4))//5
    m6=((((y-(500*m1))-(100*m2))-(50*m3))-(10*m4))-5*m5
    
    z=m1+m2+m3+m4+m5+m6
    
    print(z)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

while True:
   x = int(input())
   if x == 0:
      break
   
   y = 1000 - x;
   a = y % 500
   b = a % 100
   c = b % 50
   d = c % 10
   e = d % 5
   z = y // 500 + a // 100 + b // 50 + c // 10 + d // 5 + e
   
   print(z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(n):
	a = 1000 - n
	y = [500, 100, 50, 10, 5, 1]
	ans = 0
	for i in y:
		ans += a // i
		a %= i
		if a == 0:
			return ans
def resolve():
	while True:
		v = int(input())
		if v == 0:
			return
		print(calc(v))
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
for i in range(5):
    a=int(input())
    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
    if a==0:break
    print(b+c+d+e+f+g)

Submission status: Accepted

Solution code:
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(int(sum))

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    else:
        change = 1000-n
        sum_coin = 0
        coin = [500,100,50,10,5,1]

        for i in coin:
            r = change // i
            change %= i
            sum_coin += r
    
        print(sum_coin)

Submission status: Accepted

Solution code:
while True:
    x=int(input())
    if x==0:
        break
    else:
        y=1000-x
        y1=y//500
        y2=(y-500*y1)//100
        y3=(y-500*y1-100*y2)//50
        y4=(y-500*y1-100*y2-50*y3)//10
        y5=(y-500*y1-100*y2-50*y3-10*y4)//5
        y6=(y-500*y1-100*y2-50*y3-10*y4-5*y5)//1
        z=y1+y2+y3+y4+y5+y6
        print(z)

Submission status: Accepted

Solution code:
while True:
    kei = 0
    i = int(input())
    if i == 0:
        break
    else:
        num = 1000 - i
        if num >= 500:
            num %= 500
            kei += 1
        if num >= 100:
            num1 = num // 100
            kei += num1
            num %= 100
        if num >= 50:
            num %= 50
            kei += 1
        if num >= 10:
            num1 = num // 10
            kei += num1
            num %= 10
        if num >= 5:
            num %= 5
            kei += 1
        if num >= 1:
            num1 = num // 1
            kei += num1
    print(kei)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=0
for i in range(7):
  N=int(input())
  if N==0:
    break
  N=1000-N
  print(N//500+(N//100)%5+(N//50)%2+(N//10)%5+(N//5)%2+N%5)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    c = 1000-n
    print(c//500 + c%500//100 + c%100//50 + c%50//10 + c%10//5 + c%5)

Submission status: Accepted

Solution code:
coins=[500,100,50,10,5,1]
while 1:
    v=int(input())
    if v==0:
        break
    else:
        change=1000-v
        cnt=0
        for coin in coins:
            c=change//coin
            if c!=0:
                cnt+=c
                change-=coin*c
        print(cnt)

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:
def main():
    N = 1000 - int(input())
    while N != 1000:
        ans = 0
        while N >= 500:
            ans += 1
            N -= 500
        while N >= 100:
            ans += 1
            N -= 100
        while N >= 50:
            ans += 1
            N -= 50
        while N >= 10:
            ans += 1
            N -= 10
        while N >= 5:
            ans += 1
            N -= 5
        while N >= 1:
            ans += 1
            N -= 1
        print(ans)
        N = 1000 - int(input())

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    while True:
        N = int(input())
        if N == 0:
            return

        o = 1000 - N
        ans = 0
        coin = [500, 100, 50, 10, 5, 1]
        for c in coin:
            set = o // c
            ans += set
            o -= c * set

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nyuuryoku=[]
while True:
	bbb=int(input())
	if bbb==0:	
		break
	a=1000-bbb
	gohyaku=int(a/500)
	hyaku=int((a-(500*gohyaku))/100)
	gojuu=int((a-(500*gohyaku)-(100*hyaku))/50)
	juu=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu))/10)
	go=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10))/5)
	iti=int((a-(500*gohyaku)-(100*hyaku)-(50*gojuu)-(juu*10)-(go*5))/1)
	print(go+gohyaku+gojuu+hyaku+iti+juu)

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:
while True:
    n=int(input())
    count=0
    if n==0:
        break
    x=1000-n
    if x>=500:
        count+=1
        x-=500
    a=x//100
    count+=a
    if a>0 :
        x=x-a*100
    if x>=50 :
        count+=1
        x-=50
    b=x//10
    count+=b
    if b>0 :
        x=x-b*10
    if x>=5 :
        count+=1
        x-=5
    count+=x
    
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(n):
    t=1000-n
    cnt=0
    for i in range(len(c)):
        while t//c[i]>0:
            t-=c[i]
            cnt+=1
    return cnt


for i in range(5):
    n=int(input())
    if n==0:exit()
    print(solve(n))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

    ch = 1000 - n
    ans = 0
    for i in range(6):
        num = int(ch / c[i])
        ans += num
        ch -= num * c[i]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    charge = 1000 - n
    cnt = 0
    if charge >= 500:
        cnt += 1
        charge -= 500
    cnt += charge // 100
    charge %= 100

    if charge >= 50:
        cnt += 1
        charge -= 50
    cnt += charge // 10
    charge %= 10

    if charge >= 5:
        cnt += 1
        charge -= 5
    cnt += charge

    print(cnt)

Submission status: Accepted

Solution code:
while True:
	try:
		turi = 1000 - input()
		if turi == 1000:
			break
		how = 0
		while True:
			if turi >= 500:	
				turi -= 500
				how += 1
			else:
				break
		while True:
			if turi >= 100:
				turi -= 100
				how += 1
			else:
				break
		while True:
			if turi >= 50:
				turi -= 50
				how += 1
			else:
				break
		while True:
			if turi >= 10:
				turi -= 10
				how += 1
			else:
				break
		while True:
			if turi >= 5:
				turi -= 5
				how += 1
			else:
				break
		while True:
			if turi >= 1:
				turi -= 1
				how += 1
			else:
				break
		print how
	except EOFError:
		break

Submission status: Runtime Error

Solution code:
while 1:
    n = 1000 - input()
    if n==0: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: Runtime Error

Solution code:
for e in iter(input,'0'):
while 1:
 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: Runtime Error

Solution code:
while True:
    c =0
    a = int(input())
    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: Runtime Error

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

def count(x, y):
    ret = 0
    while x >= y:
        x -= y
        ret += 1
    return 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: Runtime Error

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]
            count += 1
        else:
            i += 1
    print count

Submission status: Runtime Error

Solution code:
c = [500,100,50,10,5,1]
while True:
    e = 1000 - 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: WA: Presentation Error

Solution code:
import sys
x=sys.stdin.read().split()
        
def otsuri(x):
    a=0
    y=1000-x
    if y==1000:
        return''
    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)