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 <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  while (1) {
    int in;
    cin >> in;
    if (in == 0) break;
    int n = 1000 - in;

    int c = 0;
    c += n / 500;
    n %= 500;

    c += n / 100;
    n %= 100;

    c += n / 50;
    n %= 50;

    c += n / 10;
    n %= 10;

    c += n / 5;
    n %= 5;

    c += n / 1;
    n %= 1;

    println(str(c));
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	n = 1000 - n;
	int count = 0;
	count += n / 500;
	n %= 500;
	count += n / 100;
	n %= 100;
	count += n / 50;
	n %= 50;
	count += n / 10;
	n %= 10;
	count += n / 5;
	n %= 5;
	count += n;
	cout << count << endl;
}

int main()
{
	solve();
	return(0);
}

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

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

C++: #include <stdio.h>
int main()
{
  int a,b,c,d,e,f,sum,ch ;
  scanf("%d",&sum);
  ch=1000-sum;
  printf("%d\n",ch=1000-sum);
  a=ch/500 ,b=(ch-500*a)/100 , c=(ch-500*a-100*b)/50 , d=(ch-500*a-100*b-50*c)/10 , e=(ch-500*a-100*b-50*c-10*d)/5 , f=(ch-500*a-100*b-50*c-10*d-5*e);
  printf("%d %d %d %d %d\n" ,a,b,c,d,e,f );
    printf("Change=%d\n",a+b+c+d+e+f);

  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(a[i]) {
        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 <iostream>
using namespace std;

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

C++: #include <iostream>
using namespace std;
 
int main() {
	int tnok, yj;
	cin >> tnok;
	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;
	}
	if(tnok >= 4){
		yj = yj + 4;
		tnok = tnok - 4;
	}
	else if(tnok >= 3){
		yj = yj + 3;
		tnok = tnok - 3;
	}
	else if(tnok >= 2){
		yj = yj + 2;
		tnok = tnok - 2;
	}
	else if(tnok >= 1){
		yj = yj + 1;
		tnok = tnok - 1;
	}
	cout << yj <<endl;
 
	return 0;
}

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

int main(){
    int n;
    int charge;
    int cnt = 0;

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

    while(cin >> n, n != 0){
        charge = 1000 - n;
        for(int i=0; i<6; i++){
            int j = 0;
            while(charge - coin[i] * j >= coin[i]){
                j++;
            }
            charge -= coin[i] * j;
            cnt += j;
        }

        cout << cnt << endl;
        cnt = 0;
    }
    return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {
  while(true) {
    //input
    int num;
    cin >> num;
    //if 0 finish
    if(num==0) break;

    //oturi
    num = 1000 - num;

    int ans = 0;

    //500yen
    if(num>=500) {
      ans++;
      num-=500;
    }

    //100yen
    while(num>=100) {
      ans++;
      num-=100;
    }

    //50yen
    if(num>=50) {
      ans++;
      num-=50;
    }

    //10yen
    while(num>=10) {
      ans++;
      num-=10;
    }

    //5yen
    if(num>=5) {
      ans++;
      num-=5;
    }

    //1yen
    while(num>=1) {
      ans++;
      num-=1;
    }

    cout << ans << endl;

  }

  return 0;
}

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

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