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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int money;
  while(cin>>money){
    if(money==0)break;
    int oturi = 1000-money;
    int ans = 0;
    ans += oturi/500;
    oturi%=500;
    ans += oturi/100;
    oturi%=100;
    ans += oturi/50;
    oturi%=50;
    ans += oturi/10;
    oturi%=10;
    ans += oturi/5;
    oturi%=5;
    ans += oturi;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int score;
int use(int money, int coin){
	int ans = money / coin;
	score += ans;
	return ans;
}

int main(){
	while (1){
		score = 0;
		int money;
		scanf("%d", &money);
		if (money == 0) return 0;
		money = 1000 - money;
		money -= use(money, 500) * 500;
		money -= use(money, 100) * 100;
		money -= use(money, 50) * 50;
		money -= use(money, 10) * 10;
		money -= use(money, 5) * 5;
		money -= use(money, 1) * 1;
		printf("%d\n", score);
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		while (b!=0)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			else if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			else if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			else if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			else if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			else if (b >= 1)
			{
				b = b - 1;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl
#define MOD  998244353

int main() {
	lint N;
	while (cin >> N, N != 0) {
		N = 1000 - N;
		lint ans = 0;
		ans += N / 500;
		N %= 500;
		ans += N / 100;
		N %= 100;
		ans += N / 50;
		N %= 50;
		ans += N / 10;
		N %= 10;
		ans += N / 5;
		N %= 5;
		ans += N / 1;
		N %= 1;
		cout << ans << enld;
	}
}

C++: #import<cstdio>
int main(){
	int i,n,c[]={0,1,5,10,50,100,500};
	for(;*c=0,scanf("%d",&n),n;printf("%d\n",*c)){
		for(n=1000-n,i=6;i;i--){
			for(;n>=c[i];){
				n-=c[i],*c++;
			}
		}
	}
}

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

int minus_five(int f, int* money)
{
  if (*money >= f)
  {
    *money -= f;
    return 1;
  }
  return 0;
}

int minus_one(int o, int* money)
{
  int result = *money / o;
  *money = *money - result*o;
  return result;
}

int main(void)
{
  int pay;
  int coin;
  while (true)
  {
    cin >> pay;
    if ( pay == 0 ) break;
    pay = 1000 - pay;
    coin = 0;

    coin += minus_five(500, &pay);
    coin += minus_one (100, &pay);
    coin += minus_five( 50, &pay);
    coin += minus_one ( 10, &pay);
    coin += minus_five(  5, &pay);
    coin += minus_one (  1, &pay);

    cout << coin << endl;
  }
  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++: #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++;
    }
 }
 cout<<count<<"\n";
 count=0;
}
return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
	int n;
	while (cin >> n && n)
	{
	cin >> n;
	int remaind = 1000 - n;
	int ans = 0;
	for (int i = 0; i < 6; i++)
	{
		ans += remaind / coins[i];
		remaind %= coins[i];
	}
	cout << ans << endl;
	}
	return 0;
}

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

void solve(int price) {
    int dif = 1000 - price;
    int all = 0;
    while (0 < dif) {
        int count = 0;
        int d = 0;
        if (500 <= dif) {
            d = 500;
        } else if (100 <= dif) {
            d = 100;
        } else if (50 <= dif) {
            d = 50;
        } else if ( 10 <= dif ) {
            d = 10;
        } else if (5 <= dif) {
            d = 5;
        } else {
            d = 1;
        }
        count = dif / d;
        dif -= count * d;
        all += count;
    }
    cout << all << endl;
}

int main() {
    int price;
    while(true) {
        cin >> price;
        if (price == 0) break;
        else solve(price);
    }
    return 0;
}

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

C++: #include<stdio.h>
int n;
int ans;
int i;
int c[6]={500,100,50,10,5,1};

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