Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c,l,k,h,j,r,f;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/50;
	i=z%50;
	l=i/10;
	k=i%10;
	h=k/5;
	j=k%5;
	r=j/1;
	f=j%1;
	c=b+y+m+l+h+r;
	printf("%d\n",c);
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,s,d,f;
	scanf("%d",&a);
	while(a!=0){
	d=0;
	s=1000-a;
	while(s!=0){
	if(s>=500){
		s=s-500;
		d++;
	}
	else if(s>=100){
		s=s-100;
		d++;
	}
	else if(s>=50){
		s=s-50;
		d++;
	}
	else if(s>=10){
		s=s-10;
		d++;
	}
	else if(s>=5){
		s=s-5;
		d++;
	}
	else if(s>=1){
		s=s-1;
		d++;
	}
	}
	printf("%d\n",d);
	scanf("%d",&a);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
  int a,cnt,b,c[5]={500,100,50,10,5};
  while(cin>>a&&a){
    cnt=0;
    b=1000-a;
    for(int i=0;i<5;i++) cnt+=b/c[i],b%=c[i];
    cnt+=b;
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int money = 1000;
	int pay, change, i;

	cin >> pay;
	change = money - pay;

	while(1){
	if(change == 0 || change == 1000) break;
	else if(change < 0 || 1000 < change) break;
	while(1){
		if(change - 500 >= 0){
			i += 1;
			change -= 500;
			break;
		}
		else if(change - 100 >= 0){
			i += 1;
			change -= 100;
			break;
		}
		else if(change - 50 >= 0){
                        i += 1;
                        change -= 50;
                        break;
                }
		else if(change - 10 >= 0){
                        i += 1;
                        change -= 10;
                        break;
                }
		else if(change - 5 >= 0){
                        i += 1;
                        change -= 5;
                        break;
                }
		else{
			i += 1;
			change -= 1;
			break;
		}
	}
	}
	
	if(pay == 0 ) return 0;
        else if(pay < 0 || 1000 < pay) return 0;
	else cout << i << "\n";

	
	return 0;
}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  while (1) {
    int in;
    cin >> in;
    if (in == 0) break;
    int n = 1000 - in;

    int c = 0;
    c += n / 500;
    n %= 500;

    c += n / 100;
    n %= 100;

    c += n / 50;
    n %= 50;

    c += n / 10;
    n %= 10;

    c += n / 5;
    n %= 5;

    c += n / 1;
    n %= 1;

    println(str(c));
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	n = 1000 - n;
	int count = 0;
	count += n / 500;
	n %= 500;
	count += n / 100;
	n %= 100;
	count += n / 50;
	n %= 50;
	count += n / 10;
	n %= 10;
	count += n / 5;
	n %= 5;
	count += n;
	cout << count << endl;
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
using namespace std;

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value/500; value%=500;
coins += value/100; value%=100;
coins += value/50; value%=50;
coins += value/10; value%=10;
coins += value/5; value%=5;
coins += value;
cout << coins << endl;
}
return 0;
}

C++: #include <stdio.h>
int main()
{
  int a,b,c,d,e,f,sum,ch ;
  scanf("%d",&sum);
  ch=1000-sum;
  printf("%d\n",ch=1000-sum);
  a=ch/500 ,b=(ch-500*a)/100 , c=(ch-500*a-100*b)/50 , d=(ch-500*a-100*b-50*c)/10 , e=(ch-500*a-100*b-50*c-10*d)/5 , f=(ch-500*a-100*b-50*c-10*d-5*e);
  printf("%d %d %d %d %d\n" ,a,b,c,d,e,f );
    printf("Change=%d\n",a+b+c+d+e+f);

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
	int a[6], sum[5] = {0};
    int i = 0;
    while(a[i]) {
        std::cin >> a[i];
        if (a[i] == 0) {
            break;
        }
        i++;
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
	int x;
	cin>>x;	
	while(x!=0){
	
	int n;
	x=1000-x;
	
	if(x>=500){
		n=x/500;
		x=x%500;
	}
	if(x>=100){
		n+=x/100;
		x=x%100;
	}
	if(x>=50){
		n+=x/50;
		x=x%50;
	}
	if(x>=10){
		n+=x/10;
		x=x%10;
	}
	if(x>=5){
		n+=x/5;
		x=x%5;
	}
	n+=x;
	cout<<n<<endl;
	cin>>x;
	}
	
	
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	int tnok, yj;
	cin >> tnok;
	tnok = 1000 - tnok;
	if(tnok >= 500){
		yj = 1;
		tnok = tnok - 500;
	} else {
		yj = 0;
	}
	if(tnok >= 400){
		yj = yj + 4;
		tnok = tnok - 400;
	}
	else if(tnok >= 300){
		yj = yj + 3;
		tnok = tnok - 300;
	}
	else if(tnok >= 200){
		yj = yj + 2;
		tnok = tnok - 200;
	}
	else if(tnok >= 100){
		yj = yj + 1;
		tnok = tnok - 100;
	}
	if(tnok >= 50){
		yj = yj + 1;
		tnok = tnok - 50;
	}
	if(tnok >= 40){
		yj = yj + 4;
		tnok = tnok - 40;
	}
	else if(tnok >= 30){
		yj = yj + 3;
		tnok = tnok - 30;
	}
	else if(tnok >= 20){
		yj = yj + 2;
		tnok = tnok - 20;
	}
	else if(tnok >= 10){
		yj = yj + 1;
		tnok = tnok - 10;
	}
	if(tnok >= 5){
		yj = yj + 1;
		tnok = tnok - 5;
	}
	if(tnok >= 4){
		yj = yj + 4;
		tnok = tnok - 4;
	}
	else if(tnok >= 3){
		yj = yj + 3;
		tnok = tnok - 3;
	}
	else if(tnok >= 2){
		yj = yj + 2;
		tnok = tnok - 2;
	}
	else if(tnok >= 1){
		yj = yj + 1;
		tnok = tnok - 1;
	}
	cout << yj <<endl;
 
	return 0;
}

C++: #include <iostream>
using namespace std;

int main(){
    int n;
    int charge;
    int cnt = 0;

    int coin[] = {500, 100, 50, 10, 5, 1};

    while(cin >> n, n != 0){
        charge = 1000 - n;
        for(int i=0; i<6; i++){
            int j = 0;
            while(charge - coin[i] * j >= coin[i]){
                j++;
            }
            charge -= coin[i] * j;
            cnt += j;
        }

        cout << cnt << endl;
        cnt = 0;
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,s,ss,z,z1,z2,z3,z4;
	scanf("%d",&n);
	ss=1000-n;
	s=ss/500;
	z=ss%500;
	s+=z/100;
	z1=z%100;
	s+=z1/50;
	z2=z1%50;
	s+=z2/10;
	z3=z2%10;
	s+=z3/5;
	z4=z3%5;
	s+=z4/1;
	printf("%d\n",s);
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  while(true) {
    //input
    int num;
    cin >> num;
    //if 0 finish
    if(num==0) break;

    //oturi
    num = 1000 - num;

    int ans = 0;

    //500yen
    if(num>=500) {
      ans++;
      num-=500;
    }

    //100yen
    while(num>=100) {
      ans++;
      num-=100;
    }

    //50yen
    if(num>=50) {
      ans++;
      num-=50;
    }

    //10yen
    while(num>=10) {
      ans++;
      num-=10;
    }

    //5yen
    if(num>=5) {
      ans++;
      num-=5;
    }

    //1yen
    while(num>=1) {
      ans++;
      num-=1;
    }

    cout << ans << endl;

  }

  return 0;
}