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(){
  int x ;
  while(1){
    cin >> x ;
    int total = 0;
    if( x==0 )break;
    int yen500 = 0;
    int yen100 = 0;
    int yen50 = 0;
    int yen10 = 0;
    int yen5 = 0;
    int yen1 = 0;
    x = 1000- x;
    yen500 = x /500 ;
    x = x%500;
    yen100 = x /100;
    x = x%100;
    yen50 = x / 50 ;
    x = x %50;
    yen10 = x/10;
    x = x%10;
    yen5 = x/5;
    x = x%5;
    yen1 = x;
    total = yen500 + yen100 + yen50 + yen10 + yen1 + yen5;
    cout << total << endl;
  }
}

C++: #include <iostream>

using namespace std;

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

int main()
{
    int inp;

    while (cin >> inp, inp) {
        int ans = 0;

        inp = 1000 - inp;
        for (int i = 0; i < 7; i++) {
            if (inp <= 0)
                break;
            else if (inp / m[i]) {
                ans += inp / m[i];
                inp = inp % m[i];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main(void){
  int coins[] = {500, 100, 50, 10, 5, 1};

  while(1){
  int ans = 0, n; cin >> n;
  if(n == 0) return 0;
  n = 1000 - n;
  for(int i=0; i < 6; i++){
    while(n >= coins[i]){
      ans++;
      n -= coins[i];
    }
  }
  cout << ans << endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	price=1000-price;
	while(1){
		if(flag==1){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	if(coins!=0){
	cout<<coin<<endl;
	}
	return 0;

}

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

int main(){
    int n;
    while(cin >> n, n){
        n = 1000 - n;
        cout << n/500 + n%500/100 + n%100/50 + n%50/10 + n%10/5 + n%5 << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

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

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

        int r = 1000 - m;
        int sum = 0;
        for( auto const& c : cset ) {
            for(;;) {
                if ( r - c >= 0 ) {
                    ++sum;
                    r -= c;
                } else {
                    break;
                }
            }
        }
        cout << sum << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 ??????????????????JOI?????¨?????§?????????????????????
 JOI?????¨???????????¬??¨???500??????100??????50??????10??????5??????1?????????????????°???????????????
 ????????????????????°????°??????????????????????????????????????????????????????????
 ????????????JOI?????¨?????§????????????????????¬?????§1000?????????1??????????????????
 ???????????????????????????????????¬??¨????????°????±???????????????°????????????????????????
 =================================================================
 ?§£??¬=============================================================
 ????????????
 ================================================================
 */

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    int K[6] = {500,100,50,10,5,1};
    while(cin >> N,N){
        int res = 0;
        N = 1000 - N;
        for(int i = 0; i < 6;i++){
            res += N/K[i];
            N %= K[i];
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
	int n;
	while(cin >> n, n){
		int change = 1000 - n;
		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 <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
 
using namespace std;
 
 
int main(){
 
    int coin[6] ={ 500,100,50,10,5,1 },sum,price;
 
    while(true){
        scanf("%d",&price);
        if(price == 0)break;
 
        sum = 0;
 
        price = 1000 - price;
 
        for(int i = 0; i <= 5; i++){
            while(price >= coin[i]){
                price -= coin[i];
                sum++;
            }
        }
 
        printf("%d\n",sum);
    }
 
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,count,maisu = 0,oturi[1000] = {};
  int money2[6] = {500,100,50,10,5,1};

  for(int i = 0;i >= 0;i++){
    cin >> money;
    count++;
    if(money == 0)
      break;
    oturi[i] = 1000 - money;
  }

  for(int j = 0;j < count;j++){ 
    for(int i = 0;i < 6;i++){
      maisu += oturi[j] / money2[i];
      oturi[j] %= money2[i];
    }
  }
  cout << maisu << endl;
    
    return 0;
  }

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

//????¬??????§?????£???????????°????±???????
int coin(int X){
    int ans = 0;
    //500
    ans = X / 500;

    //100
    ans = ans + (X % 500) / 100;

    //50
    ans = ans + ((X % 500) % 100) / 50;

    //10
    ans = ans + (((X % 500) % 100) % 50) / 10;

    //5
    ans = ans + ((((X % 500) % 100) % 50) % 10) / 5;

    //1
    ans = ans + (((((X % 500) % 100) % 50) % 10) % 5);

    return  ans;
}

int main(void){

    int i = 0;
    int ans[5];
    int input;
    while(1){
        cin >> input;
        if(input == 0){ break;}
        else{
            ans[i] = coin(1000-input);
        }
        i++;
    }

    for(int j = 0; j < i; j++){
        cout << ans[j] << endl;
    }

    return 0;
}