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>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        if (a[i] == 0) break;
        
        int count = 0;
        int n = 1000-a[i];
        
        count += (n - n % 500) / 500;
        count += (n - n % 100) / 100;
        count += (n - n % 50) / 50;
        count += (n - n % 10) / 10;
        count += (n - n % 5) / 5;
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<int> ans;
  int coin[6] = {500, 100, 50, 10, 5, 1};
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;

    int oturi = 1000 - n;
    int res = 0;
    rep(i,6) {
      if (oturi == 0) break;
      if (oturi < coin[i]) continue;
      res += oturi / coin[i];
      oturi = oturi % coin[i];
    }
    ans.push_back(res);
  }
  rep(i,ans.size()) cout << ans[i] << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){

	while(1){
		int a; cin >> a;
		if(a == 0) return 0;
		a = 1000 - a;

		int ans = 0;

		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;

		cout << ans << endl;
	}

}

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

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num = 0;

		if (cost_return < 5) {
			num = cost_return;
			break;
		}
		else {
			if (cost_return < 10) {
				num = 1 + cost_return - 5;
			}
			/*else {
				if (cost_return < 100) {
					num += (cost_return / 10);
					if (cost_return % 10 < 5) {
						num += cost_return % 10
					}
					else {
						num += 1 + cost_return - 5;
					}
				}
				else
				{
					if (cost_return < 500) {
						num += (cost_return / 100);
						if (cost_return % 100 < 5) {
							num += cost_return % 10
						}
						else {
							num += 1 + cost_return - 5;
						}
					}
				}
			}*/
		}
		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		/*if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1){
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}*/
	}
	

	for (int i = 0; i < j;++i) {
		CO num_answer E
	}
}

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

int main() {
	int x;
	cin>>x;
	int sum=1000-x;
	int ans=0;
	if(sum!=0)ans+=sum/500;
	sum%=500;
	if(sum!=0)ans+=sum/100;
	sum%=100;
	if(sum!=0)ans+=sum/50;
	sum%=50;
	if(sum!=0)ans+=sum/10;
	sum%=10;
	if(sum!=0)ans+=sum/5;
	sum%=5;
	ans+=sum;
	cout<<ans<<endl;
	// your code goes here
	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(1){
        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 <algorithm>
#include <iostream>
#include <vector>

#include <stdlib.h>

using namespace std;

#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define SORT(x, n) sort(begin(x),begin(x)+n)

#define INF 2000000000000

int calc(int value){
	if(value - 500 >= 0){
		return value - 500;
	}
	else if(value - 100 >= 0){
		return value - 100;
	}
	else if(value - 50 >= 0){
		return value - 50;
	}
	else if(value - 10 >= 0){
		return value - 10;
	}
	else if(value - 5 >= 0){
		return value - 5;
	}
	else{
		return value - 1;
	}
}

int main()
{
	int price, oturi;
	while(true)
	{
		cin >> price;
		if(price == 0){ break; }
		oturi = 1000 - price;
		
		int count=0;
		while(true)
		{
			oturi = calc(oturi);
			//cout << oturi << endl;
			count++;
			if(oturi == 0){ break; }
		}
		
		cout << count << endl;
	}
	
	/*
	for(auto a : W){
		cout << a << endl;
	}
	*/
	
}

C++: #include<iostream>
using namespace std;
int main(){
    int n,ans =0;
    int coin[6] = {500,100,50,10,5,1};
    
    while(cin>>n)
    {
        n = 1000-n;
        for(int i = 0; 1 < 6; i++)
        {
            ans += n/coin[i];
            n %= coin[i];
        }
    }
  return 0;
}

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