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() {
	while(1){
		int tnok, yj;
		cin >> tnok;
		if (tnok == 0){
			return 0;
		}
		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;
		}
		cout << tnok + yj <<endl;
	}
}

C++: g#include <iostream>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int change = 1000 - n;
        int count = 0;
        if (change >= 500) {
            change -= 500;
            count++;
        } 
        if (change >= 100) {
            int coin_100 = change / 100;
            change -= 100 * coin_100;
            count += coin_100;
        } 
        if (change >= 50) {
            change -= 50;
            count++;
        }
        if (change >= 10) {
            int coin_10 = change / 10;
            change -= 10 * coin_10;
            count += coin_10;
        }
        if (change >= 5) {
            change -= 5;
            count++;
        }
        count += change;
        cout << count << endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

int main(void)
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		int cnt = 0;
		int o = 1000 - n;
		
		while(o >= 500){
			cnt++;
			o -= 500;
		}
		while(o >= 100){
			cnt++;
			o -= 100;
		}
		while(o >= 50){
			cnt++;
			o -= 50;
		}
		while(o >= 10){
			cnt++;
			o -= 10;
		}
		while(o >= 5){
			cnt++;
			o -= 5;
		}
		while(o >= 1){
			cnt++;
			o -= 1;
		}
		printf("%d\n", cnt);
	}
	
	return (0);
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num = 0;
	while (cin >> pay)

	{
		if (!pay) break;

		pay = 1000 - pay;
		if (pay / 500 == 1){
			pay -= 500;
			num++;
		}
		for (;;){
			if (pay / 100 >= 1){
				pay -= 100;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 50 >= 1){
				pay -= 50;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 10 >= 1){
				pay -= 10;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 5){
				pay -= 5;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 1){
				pay -= 1;
				num++;
			}
			else break;
		}
		cout << num << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		if (b >= 500)
		{
			b = b - 500;
			c++;
		}
		else if (b >= 100)
		{
			b = b - 100;
			c++;
		}
		else if (b >= 50)
		{
			b = b - 50;
			c++;
		}
		else if (b >= 10)
		{
			b = b - 10;
			c++;
		}
		else if (b >= 5)
		{
			b = b - 5;
			c++;
		}
		else if (b >= 1)
		{
			b = b - 1;
			c++;
		}
		cout << c << endl;
	}	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
const int value[6] = {1, 5, 10, 50, 100, 500};
void pay(int n) {
    int rest = 1000 - n;
    int ans = 0;
    for (int i = 5; i >= 0; i--) {
        ans += (rest / value[i]);
        rest -= rest / value[i] * value[i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        pay(n);
    }
    return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

int main()
{
  cin >>N;
  N =1000-N;
  int ans = 0;
  int c[6] ={500,100,50,10,5,1};
  for(int i =0;i < 6;i++){
   while(N/c[i]){
      ans++;
      N -=c[i];
    }
  }
  cout <<ans<<endl;
  return 0;
}

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<iostream>
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int rest=1000-n;
		int fihu=rest/500;
		int hun=(rest-fihu*500)/100;
		int fif=(rest-fihu*500-hun*100)/50;
		int ten=(rest-fihu*500-hun*100-fif*50)/10;
		int five=(rest-fihu*500-hun*100-fif*50-ten*10)/5;
		int one=rest%5;
		cout<<fihu+hun+fif+ten+five+one<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(1){
	cin>>a;
    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))/1;
        cout<<b+c+d+e+f+g<<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; }

		ans = 0;
		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 <iostream>

using namespace std;

int main(){
	int pay=0,coin=0;
	cin>>pay;
	pay=1000-pay;
	cout<<pay<<endl;
	if(pay/500>=1){
		pay-=500;
		coin++;
	}
	if(pay>=100){
		coin+=pay/100;
		pay-=100*(pay/100);
	}
	if(pay>=50){
		coin+=pay/50;
		pay-=50*(pay/50);
	}
	if(pay>=10){
		coin+=pay/10;
		pay-=10*(pay/10);
	}
	if(pay>=1){
		coin+=pay;
	}
	cout<<coin<<endl;
}