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 <bits/stdc++.h>
using namespace std;

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1){
int b=a/1;
i+=b;
a-=1*b;
}
}
return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int ans=0;
    while(cin>>n,n){
        int hoge=1000-n;
        int a=hoge/500;
        hoge-=a*500;
        ans+=a;
        a=hoge/100;
        hoge-=a*100;
        ans+=a;
        a=hoge/50;
        hoge-=a*50;
        ans+=a;
        a=hoge/10;
        hoge-=a*10;
        ans+=a;
        a=hoge/5;
        ans+=a;
        hoge-=a*5;
        cout<<ans+hoge<<endl;
        
    }
}

C++: #include<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0, coin[] = { 500,100,50,10,5 };

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

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

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

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

int main() {

	int change, coins;

	while (cin >> change, change) {
		change = 1000 - change;

		coins = 0;
		for (int i = 0; i < 6; ++i) {
			if (change >= coin[i]) {
				coins += change / coin[i];
				change -= coins * coin[i];
				if (!change)
					break;
			}
		}
		cout << coins << endl;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

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

C++: #include <stdio.h>
#include <stdlib.h>

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

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

	for (int i = 5; i >= 0; i--){
		if (oturi >= a[i]){
			div_t d;

			d = div(oturi, a[i]);
			oturi = oturi - a[i] * d.quot;
			count = count + d.quot;
		}
	}
	printf("%d\n",count);

	return 0;

}

C++: #include<iostream>

using namespace std; 

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

int main() {
    int n;
    int count = 0;
    while (cin >> n && n != 0) {
        n = 1000-n;
        for (int i = 0; i < 6; i++) {
            count += n/denominations[i];
            n -= denominations[i]*(n/denominations[i]);
        }
        cout << count << endl;
        count = 0; 
    }
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

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

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	cin>>a;
	a=1000-a;
	if(a>499){
		a=a-500;
		s=s+1;
	}
	for(i=0;i<4;i++){
		if(a>99){
			a=a-100;
			s=s+1;
		}
	}
	if(a>49){
		a=a-50;
		s=s+1;
	}
	for(i=0;i<4;i++){
		if(a>9){
			a=a-10;
			s=s+1;
		}
	}
	if(a>4){
		a=a-5;
		s++;
	}
	s=s+a;
	cout<<s<<endl;
}

C++: #include <iostream>
main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int m,n,a,b,c,d,e,f,g;
    while(1){
        cin >> m;
        if(m==0){
            break;
        }
        a=1000-m;
        b=a/500;
        c=(a-500*b)/100;
        d=(a-500*b-100*c)/50;
        e=(a-500*b-100*c-50*d)/10;
        f=(a-500*b-100*c-50*d-e*10)/5;
        g=(a-500*b-100*c-50*d-e*10-f*5)/1;
        n=b+c+d+e+f+g;
        cout << n << endl;
    }
    
}

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

int main(){
    int N;
    while(cin>>N,N){
        int money[6]={500,100,50,10,5,1},ans=0;
        N=1000-N;
        for(int i=0;i<6;i++){
            while(N-money[i]>=0) N-=money[i],ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}