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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int N;
	scanf("%d",&N);
	int n = 1000 - N;
	int cnt = 0;
	if(500 <= n){
		n -= 500;
		cnt++;
	}
	if(100 <= n){
		cnt += n / 100;
		n %= 100;
	}
	if(50 <= n){
		cnt += n / 50;
		n %= 50;
	}
	if(10 <= n){
		cnt += n / 10;
		n %= 10;
	}
	if(5 <= n){
		cnt += n / 5;
		n %= 5;
	}
	cnt += n;
	printf("%d\n",cnt);
    return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<m<<endl;

}

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer[5] = { 0 };

	int in = 0, change = 0, n = 0;



	for (int j = 0; j < 5; j++) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
		answer[j] = n;
	}


	for (int j = 0; j < 5; j++) {
		if (answer[j] == 0) break;
		cout << answer[j] << endl;
	}

	return 0;
}

C++: #include <iostream>

int main(){
  int a[6] = {500,100,50,10,5,1};
  int n;
  std::cin>>n;
  n=1000-n;
  int res = 0;
  for(int i=0;i<6;i++){
    res = res + n / a[i];
    n = n % a[i];
  }
  std::cout<<res<<std::endl;
  return 0;
}

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

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

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    const vector<int> coins = {500, 100, 50, 10, 5, 1};
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int ans = 0;
        for (auto c : coins) {
            int tmp = N / c;
            ans += tmp;
            N -= tmp * c;
        }
        cout << ans << endl;
    }
}

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

int main(){
	int x, y;
	while(scanf("%d", &x)){
		if(x == 0){
			break;
		}
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int ki, co;
	while (1) {
		co = 0;
		cin >> ki;
		if (ki == 0) { break; }
		ki = 1000 - ki;
		if (ki >= 500) {
			ki = ki - 500;
			co++;
			cout << co << endl;
		}
		if (ki >= 100) {
			while(1){
				ki = ki - 100;
				co++;
				if (ki < 100) { break; }
			}
			cout << co << endl;
		}
		if (ki >= 50) {
			ki = ki - 50;
			co++;
			cout << co << endl;
		}
		if (ki >= 10) {
			while(1){
				ki = ki - 10;
				co++;
				if (ki < 10) { break; }
			}
			cout << co << endl;
		}
		if (ki >= 5) {
			ki = ki - 5;
			co++;
			cout << co << endl;
		}
		if (ki >= 1) {
			while(1){
				ki = ki - 1;
				co++;
				if (ki < 100) { break; }
			}
			cout << co << endl;
		}
		cout << co << endl;
	}
	return 0;
}

C++: #include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

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

C++: #include <bits/stdc++.h>
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>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	cin >> a;
	c = 0;
	a = 1000 - a;
	b = a;
	b = a / 500;
	c = c + b;
	a = a % 500;
	b = a / 100;
	c = c + b;
	a = a % 100;
	b = a / 50;
	c = c + b;
	a = a % 50;
	b = a / 10;
	c = c + b;
	a = a % 10;
	b = a / 5;
	c = c + b;
	a = a % 5;
	b = a;
	c = c + b;
	cout << c << endl;
	return 0;
}

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

int main(){
	int money, price;
	while(cin >> price){
		money = 1000-price;
		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;
	}
	return 0;
}

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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;
    n = 1000 - n;

    long long int ans = 0;
    if ( n >= 500 ) {
      ans++;
      n -= 500;
    }
    ans += n / 100;
    n %= 100;

    if ( n >= 50 ) {
      ans++;
      n -= 50;
    }
    ans += n / 10;
    n %= 10;

    if ( n >= 5 ) {
      ans++;
      n -= 5;
    }
    ans += n / 1;

    cout << ans << endl;

  }

  return 0;

}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   return 0;
}