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(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int pay, change, i;
	
	cin >> pay;
	
	change = 1000 - pay;

	while(1){
	if(change == 0 || change == 1000) break;
	else if(change < 0 || 1000 < change) break;
	while(1){
		if(change - 500 >= 0){
			i += 1;
			change -= 500;
			break;
		}
		else if(change - 100 >= 0){
			i += 1;
			change -= 100;
			break;
		}
		else if(change - 50 >= 0){
                        i += 1;
                        change -= 50;
                        break;
                }
		else if(change - 10 >= 0){
                        i += 1;
                        change -= 10;
                        break;
                }
		else if(change - 5 >= 0){
                        i += 1;
                        change -= 5;
                        break;
                }
		else{
			i += 1;
			change -= 1;
			break;
		}
	}
	}
	
	if(pay == 0 ) return 0;
        else if(pay < 0 || 1000 < pay) return 0;
	else cout << i << "\n";

	
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/10;
	i=z%10;
	c=b+y+m;
	printf("%d\n",c);
	return 0;
}

C++: // quest1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	int result[1000], suffix = 0;

	while (1) {
		int money, reverse, count = 0;

		scanf("%d", &money);
		if (money == 0) {
			break;
		}
		reverse = 1000 - money;

		while (reverse >= 500) {
			reverse -= 500;
			count++;
		}
		while (reverse >= 100) {
			reverse -= 100;
			count++;
		}
		while (reverse >= 50) {
			reverse -= 50;
			count++;
		}
		while (reverse >= 10) {
			reverse -= 10;
			count++;
		}
		while (reverse >= 5) {
			reverse -= 5;
			count++;
		}
		while (reverse >= 1) {
			reverse -= 1;
			count++;
		}

		result[suffix++] = count;
	}

	for (int i = 0; i < suffix; i++) {
		printf("%d\n", result[i]);
	}

    return 0;
}

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

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;

  }

  return 0;

}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	if(n>=500){
		n = n%500;
		m = n/500;
	}
	if(n>=100){
		n = n%100;
		m = m+n/100;
	}
	if(n>=50){
		n = n%50;
		m = m+n/50;
	}
	if(n>=10){
		n = n%10;
		m = m+n/10;
	}
	if(n>=5){
		n = n%5;
		m = m+n/5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

	return 0;
}

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

int main() {
    while (true) {
        int input;
        cin >> input;
        if (input == 0) {
            break;
        }
        int change = 1000 - input;
        int coin = 0;
        while (change > 0) {
            if (change >= 500) {
                change -= 500;
            } else if (change >= 100) {
                change -= 100;
            } else if (change >= 50) {
                change -= 50;
            } else if (change >= 10) {
                change -= 10;
            } else if (change >= 5) {
                change -= 5;
            } else {
                change--;
            }
            coin++;
        }
        cout << coin << endl;
    }
}

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

int main()
{
int m;
while(cin>>m){
if(m==0) break;
int ans=0;
m=1000-m;
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<<ans<<endl;

}

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int n, k;
int main(){
    while(cin >> n, n){
        int res=0;
        int rest=1000-n;
        while(rest){
            if(rest-500>=0){
                res++;
                rest-=500;
                continue;
            }
            if(rest-100>=0){
                res++;
                rest -=100;
                continue;
            }
            if(rest-50>=0){
                res++;
                rest -=50;
                continue;
            }
            if(rest-10>=0){
                res++;
                rest -=10;
                continue;
            }
            if(rest-5>=0){
                res++;
                rest -=5;
                continue;
            }
            if(rest-1>=0){
                res++;
                rest -=1;
                continue;
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int coin[6] = {500,100,50,10,5,1};
	while(1){
		int in;
		cin>> in;
		if(!in) break;
		int ans=0;
		in = 1000 - in;
		for(int i=0;i<6;i++){
			int c = coin[i];
			ans += in / c;
			in = in - c*(in/c);
		}
//		assert(in==0);
		cout<< ans<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include<stdio.h>
int main (void)
{
	int n;
	int s;
	int cnt;
	
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		s=1000-n;
		while(s>=500){
			s=s-500;
			cnt++;
		}
		while(s>=100){
			s=s-100;
			cnt++;
		}
		while(s>=50){
			s=s-50;
			cnt++;
		}
		while(s>=10){
			s=s-10;
			cnt++;
		}
		while(s>=5){
			s=s-5;
			cnt++;
		}
		while(s>=1){
			s=s-1;
			cnt++;
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}