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 <stdio.h>

void main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

}

C++: #include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		cin>>n;
		int c=1000-n,ans=0;
		while(c>=500) c-=500,++ans;
		while(c>=100) c-=100,++ans;
		while(c>=50) c-=50,++ans;
		while(c>=10) c-=10,++ans;
		while(c>=5) c-=5,++ans;
		while(c>=1) c-=1,++ans;
		cout<<ans<<endl;
	}
	return 0;
}

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

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] << onum[1] << onum[2] << onum[3] << onum[4] << endl;
	return 0;
}

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

int main(void)
{
	int much;

	while(cin >> much, much > 0){
		int c = 0;

		much = 1000 - much;

		if(much >= 500){
			c += (int)(much / 500);
			much %= 500;
		}
		if(much >= 100){
			c += (int)(much / 100);
			much %= 100;
		}
		if(much >= 50){
			c += (int)(much / 50);
			much %= 50;
		}
		if(much >= 10){
			c += (int)(much / 10);
			much %= 10;
		}
		if(much >= 5){
			c += (int)(much / 5);
			much %= 5;
		}
		c += much;

		cout << c << endl;

	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
constexpr int c[] = { 500, 100, 50, 10, 5, 1 };

int main() {
  int a;
  while (cin >> a, a) {
    int b = 1000 - a;
    int ans = 0;
    for (int i = 0; i < 6; i++) {
      ans += b / c[i];
      b %= c[i];
    }
    cout << ans << "\n";
  }
}

C++: #include <iostream>

using namespace std;

int main() {
  while (true) {
    int M;
    cin >> M;
    if (M == 0) {
      break;
    }
    int m = 1000 - M;

    int ans = 0;
    while (m > 0) {
      if (m >= 500) {
        m -= 500;
      } else if (m >= 100) {
        m -= 100;
      } else if (m >= 50) {
        m -= 50;
      } else if (m >= 10) {
        m -= 10;
      } else if (m >= 5) {
        m -= 5;
      } else {
        m--;
      }

      ans++;
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=51){
		i++;
		n=(n-50);
	}
	if (n>=11){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=6){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	// Dynamic Programming
	// dp[àz] = Å¬

	const int coins[6] = { 500, 100, 50, 10, 5, 1 };

	int n;
	while ( cin >> n && n )
	{
		vector <int> dp( (1000-n)+1, 0 );
		for ( int i = 0; i < 6; i++ ) dp[coins[i]] = 1;

		for ( int i = 0; i < (1000-n)+1; i++ )
		{
			if ( dp[i] > 0 )
			{
				for ( int j = 0; j < 6; j++ )
				{
					if ( i + coins[j] < (1000-n)+1 )
					{
						if ( dp[i+coins[j]] == 0 ) dp[i+coins[j]] = dp[i] + 1;
						else dp[i+coins[j]] = min( dp[i+coins[j]], dp[i] + 1 );
					}
				}
			}
		}

		cout << dp[(1000-n)] << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  while(cin >> n, n){
    int cnt = 0, co[6] = {500, 100, 50, 10, 5, 1};
    n = 1000 - n;

    for (int i = 0; i < 6; i++){
      int a = n / co[i];
      cnt += a;
      n -= a * co[i];
    }

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

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        cost=1000-cost;
        coin+=cost/500;
        cost%=500;
        coin+=cost/100;
        cost%=100;
        coin+=cost/50;
        cost%=50;
        coin+=cost/10;
        cost%=10;
        coin+=cost/5;
        cout<<coin<<endl;
        cin>>cost;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int score;
int use(int money, int coin){
	int ans = money / coin;
	score += ans;
	return ans;
}

int main(){
	int money;
	scanf("%d", &money);
	money = 1000 - money;
	money -= use(money, 500) * 500;
	money -= use(money, 100) * 100;
	money -= use(money, 50) * 50;
	money -= use(money, 10) * 10;
	money -= use(money, 5) * 5;
	money -= use(money, 1) * 1;
	printf("%d\n", score);
	return 0;
}

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

C++: #include<cstdio>
int ks[6]={500,100,50,10,5,1};
int main(){
    for(;;){
        int ins;
        scanf("%d",&ins);
        if(ins==0)break;
        ins=1000-ins;
        int ans=0;
        for(int i=0;i<6;i++){
            ans+=ins/ks[i];
            ins-=ks[i]*(ins/ks[i]);
        }
        printf("%d\n",ans);
    }
}

C++: #include <iostream>
using namespace std;
int main(void){
   while(true){
       int a;
       cin>>a;
       if(a==0) break;
       else{
           int s=0;
           int b;
           b=1000-a;
           if(b>=500){
               s=s+1;
               b=b-500;
           }
           s=s+b/100;
           b=b%100;
           if(b>=50){
               s=s+1;
               b=b-50;
           }
           s=s+b/10;
           b=b%10;
           if(b>=5){
               s=s+1;
               b=b-5;
           }
           s=s+b;
           cout<<s;
           cout<<endl;
       }
   }
}