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>
int main()
{
    int a;
    int b,c;
    int k;
    scanf("%d",&a);
    while(a!=0){
            if(a==0)
         
                break;
                k=0;
                a=1000-a;
             
        for(b=0;a!=0;b++){
         
 
 
         if(a>=500){
            k+=1;
            a=a-500;
        }
        else if(a>=100&&a<500){
            k+=1;
            a=a-100;
        }
        else if(a>=50&&a<100){
            k+=1;
        a=a-50;
        }
        else if(a>=10&&a<50){
            k+=1;
            a=a-10;
        }
        else if(a>=5&&a<10){
            k+=1;
            a=a-5;
        }
        else if(a>=1&&a<5){
            k+=1;
            a=a-1;
        }
        }
         
         
         
        printf("%d\n",k);
        scanf("%d",&a);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,count = 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++){
    int maisu = 0;
    for(int i = 0;i < 6;i++){
      maisu += oturi[j] / money2[i];
      oturi[j] %= money2[i];
    }
    cout << maisu << endl;
  }
    return 0;
  }

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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  const int coin[] = {500, 100, 50, 10, 5, 1};
  int n, cnt = 0;

  cin >> n;
  for (int i = 0; i < 6; i++){
    while (n + coin[i] <= 1000){
      n += coin[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}

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 "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

signed main() {
  int n;
  cin >> n;
  while (n != 0) {
    int ans = 0;
    n = 1000 - n;
    ans += n / 500;
    n -= (n / 500) * 500;
    ans += n / 100;
    n -= 100 * (n / 100);
    ans += n / 50;
    n -= 50 * (n / 50);
    ans += n / 10;
    n -= 10 * (n / 10);
    ans += n / 5;
    n -= 5 * (n / 5);
    ans += n;
    cout << ans << endl;
    cin >> n;
  }
}

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

int main(){
	int x;
	while( cin >> x, x ){
		x = 1000 - x;
		int ans = 0;
		while( x > 0 ){
			ans++;
			if( x >= 500 ){
				x -= 500;
			}else if( x >= 100 ){
				x -= 100;
			}else if( x >= 50 ){
				x -= 50;
			}else if( x >= 10 ){
				x -= 10;
			}else if( x >= 5 ){
				x -= 5;
			}else{
				x--;
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
void slove(int money){
	int count=0;
	while(money>=500) {count++; money-=500;}
	while(money>=100) {count++; money-=100;}
	while(money>=50) {count++; money-=50;}
	while(money>=10) {count++; money-=10;}
	while(money>=5) {count++; money-=5;}
	while(money>=1) {count++; money-=1;}
	cout << count << endl;
}

int main(){
	int money;
	while(cin >> money)
		slove(1000-money);
	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; }

		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<cstdio>

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

int main(){
  int x,ans = 0;
  scanf("%d",&x);
  x = 1000-x;
  for(int i=0;i<6;i++){
    ans+=x/c[i];
    x%=c[i];
  }
  printf("%d\n",ans);
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	while(cin>>a){
		if(a==0)break;
		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;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {

  int value,change;
  int coins;


  while(1) {

    cin >> value;

    if(value==0) break;

    coins=0;
    change=1000-value;

    coins+=change/500;
    change%=500;

    coins+=change/100;
    change%=100;

    coins+=change/50;
    change%=50;

    coins+=change/10;
    change%=10;

    coins+=change/5;
    change%=5;

    coins+=change/1;
    change%=1;

    cout << coins << endl;

  }

  return 0;

}

C++: #include<iostream>
using namespace std;
int coin[6] = {500,100,50,10,5,1};

void slove(int money){
	int count=0;
	for(int i=0; i<6; i++){
		while(money >= coin[i]){
			count++;
			money-=coin[i];
		}
	}
	cout << count << endl;
}

int main(){
	int money;
	while(cin >> money)
		slove(1000-money);
	return 0;
}