Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}

C++: #include <iostream>
using namespace std;
int main(void){
    int i=0,n,x,c;
    while(i<5){
        cin >> x;
        if(x==0) break;
        c=0;
        n=1000-x;
        if(n>=500){
            c++;
            n-=500;
        }
        while(n>=100){
            c++;
            n-=100;
        }
        if(n>=50){
            c++;
            n-=50;
        }                
        while(n>=10){
            c++;
            n-=10;
        }
        if(n>=5){
            c++;
            n-=5;
        }
        while(n>0){
            c++;
            n-=1;
        }
        i++;
        cout<<c<<endl;
    }
    
}

C++: #include<stdio.h>
int main(void)
{
	int s,ss,sss;
	while(1){
		scanf("%d",&s);
		if(s==0) break;
		ss=1000-s;
		sss=ss/500;

		ss=ss%500;
		sss+=ss/100;

		ss=ss%100;
		sss+=ss/50;

		ss=ss%50;
		sss+=ss/10;

		ss=ss%10;
		sss+=ss/5;

		ss=ss%5;
		sss+=ss/1;

	printf("%d\n",sss);
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		int ans=0;
		
		int a;
		a=1000-n;
		ans+=a/500;
		a%=500;
		ans+=a/100;
		a%=100;
		ans+=a/50;
		a%=50;
		ans+=a/10;
		a%=10;
		ans+=a/5;
		a%=5;
		ans+=a/1;
		a%=1;
		
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << endl;
	cout << onum[1] << endl;
	cout << onum[2] << endl;
	cout << onum[3] << endl;
	cout << onum[4] << endl;
	return 0;
}

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

int main()
{

	while(true){

		int t;
		int count = 0;

		cin >> t;
		if(t==0)
			break;

		t = 1000-t;

		count += t/500;
		t = t-500*(t/500);

		count += t/100;
		t = t-100*(t/100);

		count += t/50;
		t = t-50*(t/50);

		count += t/10;
		t = t-10*(t/10);

		count += t/5;
		t = t-5*(t/5);

		count += t;

		cout << count << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int N;
int coin[6] = { 500,100,50,10,5,1 };
int ans = 0;

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n;
  while (n = in()){
    n = 1000 - n;
    int c = 0;
    for (int i = 0; i < 6; i++){
      static const int c[] = {500, 100, 50, 10, 5, 1};
      c += n / c[i];
      n %= c[i];
    }
    printf("%d\n", c);
  }

  return (0);
}

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

int main() {
  int payment;
  while (1) {
    cin >> payment;
    if (payment == 0) break;

    int change = 1000 - payment;
    int ans = 0;
    ans += change / 500; change %= 500;
    ans += change / 100; change %= 100;
    ans += change / 50; change %= 50;
    ans += change / 10; change %= 10;
    ans += change / 5; change %= 5;
    ans += change;

    cout << ans << endl;
  }

  return 0;
}

C++: #include<cstdio>
using namespace std;
int main(void){
   while(1){
      int n;
      scanf("%d",&n);
      if(n == 0) break;
      n = 1000 - n;
      int cnt = 0;
      while(1){
         if(n >= 500){
            n -= 500;
            cnt++;
         }
         else if(n >= 100){
            n -= 100;
            cnt++;
         }
         else if(n >= 50){
            n -= 50;
            cnt++;
         }
         else if(n >= 10){
            n -= 10;
            cnt++;
         }
         else if(n >= 5){
            n -= 5;
            cnt++;
         }
         else if(n >= 1){
            n -= 1;
            cnt++;
         }
         else break;
      }
      printf("%d\n",cnt);
   }
   return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int a[6]={500,100,50,10,5,1},input,count,i;
  while(1){
    cin>>input;
    if(input==0){
      break;
    }
    input=1000-input;
    for(i=0,count=0;i<6;i++){
      if(input/a[i]>0){
        count+=input/a[i];
      }
      input=input-(input/a[i])*a[i];
    }
    cout<<count<<endl;
  }
  return 0;
}