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 a;
	
	while(true)
	{
		int h=0;
	cin>>a;
	a=1000-a;
	if(a==1000)return 0;
	while(a>=500)
	{
		a=a-500;
		h=h+1;
		
	}
	while(a>=100)
	{
	a=a-100;
	h=h+1;
	}
	while(a>=50)
	{
	a=a-50;
	h=h+1;
	}
	while(a>=10)
	{
	a=a-10;
	h=h+1;
	}
	while(a>=5)
	{
	a=a-5;
	h=h+1;
	}
	while(a>=1)
	{
	a=a-1;
	h=h+1;
	}
	cout<<h<<endl;
}

		return 0;

}

C++: #include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    cin.tie(0);
    ios::sync_with_stdio(false);

    int value;
    reverse(coins, coins + 6);

    while (cin >> value, value)
    {
        value = 1000 - value;

        int ans = 0;

        REP(i, 6)
        {
            ans += value / coins[i];

            value %= coins[i];
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/

	//おつり
	while(true){
		int N;
		if(N == 0) break;
		
		int nedan;
		cin >> nedan;
		int oturi = 1000-nedan;
		int oo5 = 0,oo1 = 0,o5 = 0,o1 = 0,_5 = 0,_1 = 0;
		if(oturi >= 500)
		{
			oo5 = 1;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			oo1++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			o5 = 1;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			oo1++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			o5 = 1;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			oo1++;
			oturi -= 1;
		}

	}

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	n = 1000 - n;
	int ans = 0, i;
	int w[5] = { 500,100,50,10,1 };
	for (i = 0; i <= 5; i++) {
		ans = ans + n / w[i];
		n = n - n / w[i]*w[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
int buy,oturi,kouka;
cin>>buy;
if(!buy==0){
buy=1000;
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
int c[6] = {500,100,50,10,5,1};
int main(){

	int n;
	scanf("%d",&n);

	n = 1000 - n;
	int ans = 0;

	for(int i = 0;i < 6;i++){
		ans += (n / c[i]);

		n = n % c[i];
	}

	printf("%d\n",ans);

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    n=1000-n;
    vector<int> a={500,100,50,10,5,1};
    int ans=0;
    FORE(x,a) {
        ans+=n/x;
        n%=x;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
int total;
int change;
int count=0;
while(true){
 cin>>total;
 if(total==0){
    break;
  } 
 change=1000-total;
 while(true){
   if(change>=500){
     change-=500;
     count++;
   }else if(change>=100){
     change-=100;
     count++;
   }else if(change>=50){
     change-=50;
     count++;
   }else if(change>=10){
     change-=10;
     count++;
   }else if(change>=5){
     change-=5;
     count++;
   }else{
     change--;
     count++;
    }
 }
 count<<count<<"\n";
 count=0;
}
return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	inin(x); x = abs(x - 1000);
	int ans = 0;
	ans += x / 500; x %= 500;
	ans += x / 100; x %= 100;
	ans += x / 50; x %= 50;
	ans += x / 10; x %= 10;
	ans += x / 5; x %= 5;
	ans += x;
	cout << ans << endl;
}

C++: #include<bits/stdc++.h>
using namespace std ;
int main()
{
    int moneySet[] = { 500 , 100 , 50 , 10 , 5 , 1 } ;
    int money = 0 ;
    int Count = 0 ;
    while(1)
    {
        cin >> money ;
        if ( money == 0 ) break ;
        money = 1000 - money ;

        for (int i = 0 ; i < 6 ; i++ )
        {
            while( money >= moneySet[i] )
            {
                Count++ ;
                money -= moneySet[i] ;
            }
        }

        cout << Count << endl ;
        Count = 0 ;
    }

    return 0 ;
}

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