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 n,m,cnt;
	
	while(cin>>n){
		if(n==0)break;
		m=1000-n;
		
		for(;;){
			if(m>=500){
				m=m-500;
				//cout<<500<<endl;
				cnt++;
			}else if(m>=100&&500>m){
				m=m-100;
				//cout<<100<<endl;
				cnt++;
			}else if(m>=50){
				m=m-50;
				//cout<<50<<endl;
				cnt++;
			}else if(m>=10&&50>m){
				m=m-10;
				//cout<<10<<endl;
				cnt++;
			}else if(m<10){
				m=m-1;
				//cout<<1<<endl;
				cnt++;
			}
			if(m==0)break;
		}
		cout<<cnt<<endl;
		cnt=0;
	}
	
	return 0;
}

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

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

void solve()
{
	int ans = 0;
	for(int i=5;i>=0;i--){
		int t = a/V[i];
		a -= V[i]*t;
		ans += t;
	}
	cout << ans << endl;
}

int main()
{
	cin >> a;
	while(a){
		a = 1000-a;
		solve();
		cin >> a;
	}
	return 0;
}

C++: #include<stdio.h>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;


int main(){
	int n,ans;
	int m[]={500,100,50,10,5,1};
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		ans=0;
		n=1000-n;
		rep(i,6)while(m[i]<=n){
			ans++;
			n-=m[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int coin[]={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/coin[i];
        N%=coin[i];
    }
    printf("%d\n",ans);
    return 0;
}

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

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

int main()
{
	int p;
	while (cin >> p, p!=0)
	{
		int chg = 1000 - p;
		int c=0, cnt=0;
		while (c < 6)
		{
			while (1)
			{
				if (chg-cost[c] >= 0) { cnt++; chg-=cost[c]; }
				else break;
			}
			c++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
  int p, cnt;
  while (cin >> p) {
    if (p == 0) {
      break;
    }
    cnt = 0;
    int otsu = 1000 - p;
    if (otsu >= 500) {
      otsu -= 500;
      cnt++;
    }

    if (otsu >= 100) {
      cnt += otsu / 100;
      otsu -= otsu / 100 * 100;
    }

    if (otsu >= 50) {
      cnt += otsu / 50;
      otsu -= otsu / 50 * 50;
    }

    if (otsu >= 10) {
      cnt += otsu / 10;
      otsu -= otsu / 10 * 10;
    }

    if (otsu >= 5) {
      cnt += otsu / 5;
      otsu -= otsu / 5 * 5;
    }
    if (otsu >= 1) {
      cnt += otsu;
    }
    cout << cnt << endl;
  }
}

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

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

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

#define ALL(a) (a).begin(), (a).end()

using namespace std;

const vector<int> coin = {500, 100, 50, 10, 5, 1};

signed main(){
	while(true) {
		int n; cin >> n;
		if(n == 0) break;
		n = 1000 - n;
		int ans = 0;
		for(auto e : coin) {
			while(n >= e) {
				ans += 1;
				n -= e;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

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

int main() {

	int change, coin;
	cin >> change;

	coin = 0;
	for (int i = 0; i < 6; ++i) {
		coin += change / coins[i];
		change %= coins[i];
		if (!change)
			break;
	}
	cout << coin << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
int p=1000,s=0;
  p-=n;
  s+=p/500;
  p%=500;
  s+=p/100;
  p%=100;
  s+=p/50;
  p%=50;
  s+=p/10;
  p%=10;
  s+=p/5;
  p%=5;
  s+=p/1;
  p%=1;
  cout<<s<<endl;}

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        int Sum = 1000 - N;
        int C[] = {500, 100, 50, 10, 5, 1};
        int Res = 0;
        int i = 0;
        while (Sum > 0) {
            Res += Sum/C[i];
            Sum %= C[i];
            ++i;
        }
        cout << Res << endl;
    }

    return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n;
    int pay ;
    int cent=0;
    
    cin >> n;
    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent;
    return 0;
    
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int m;
  while(cin>>m,m){
  int co=0;
  int o=1000-m;
  if(o>500){co++;o-=500;}
  while(o>=100){co++;o-=100;}
  while(o>=50){co++;o-=50;}
  while(o>=10){co++;o-=10;}
  while(o>=5){co++;o-=5;}
  while(o>=1){co++;o--;}

  cout<<co<<endl;
  }
}