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>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int N = 1001;
const int C = 6;
const int INF = 1e9;

int main() {
  int dp[N];
  REP(i, N) dp[i] = INF;
  dp[0] = 0;
  int cs[C] = {1, 5, 10, 50, 100, 500};
  REP(i, C) FOR(j, cs[i], N) dp[j] = min(dp[j], dp[j - cs[i]] + 1);
  int N;
  while(cin >>N && N) cout <<dp[1000 - N] <<endl;
  return 0;
}

C++: #include <iostream>

using namespace std;

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

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;
}
cout<<cnt<<endl;
}
return 0;
}

C++: #include<stdio.h>

int main(void){
  int money;
  int n;
  int i;

  n = 0;

  scanf("%d", &money);

  money = 1000 - money;

  if (money >= 500){
    n += money / 500;
    money %= 500;
  }
  if (money >= 100 && money < 500){
    n += money / 100;
    money %= 100;
  }
  if (money >= 50 && money < 100){
    n += money / 50;
    money %= 50; 
  }
  if (money >= 10 && money < 50){
    n += money / 10;
    money %= 10;
  }
  if (money >= 5 && money < 10){
    n += money / 5;
    money %= 5;
  }
  

  n += money;

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

  return 0;
}

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

C++: #include <cstdio>
using namespace std;
int main()
{while(1){
 int a;
 scanf("%d",&a);
if(a==0) return 0;
 a=1000-a;
 printf("%d\n",a/500a+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5;}
}

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;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int ans=0;
    while(cin>>n,n){
        ans=0;
        int hoge=1000-n;
        int a=hoge/500;
        hoge-=a*500;
        ans+=a;
        a=hoge/100;
        hoge-=a*100;
        ans+=a;
        a=hoge/50;
        hoge-=a*50;
        ans+=a;
        a=hoge/10;
        hoge-=a*10;
        ans+=a;
        a=hoge/5;
        ans+=a;
        hoge-=a*5;
        cout<<ans+hoge<<endl;
        
    }
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main() {
	int dp[1000], tmp[] = { 500,100,50,10,5,1 }, n;
	fill_n(dp, 1000, INF);
	dp[0] = 0;
	for (int i = 0; i < 1000; i++) {
		for (int j = 0; j < 6; j++) {
			if (i - tmp[j] >= 0) dp[i] = min(dp[i], dp[i - tmp[j]] + 1);
		}
	}
	while (cin >> n, n) cout << dp[1000 - n] << endl;
}

C++: #include <iostream>

using namespace std;

main(){
  int x;
  while(1){
    cin >> x;
    if(x==0) break;

    x=1000-x;
    int ans=0;
    if(x>=500){
      ans++;
      x-=500;
    }
    while(x>=100){
      ans++;
      x-=100;
    }
    if(x>=50){
      ans++;
      x-=50;
    }
    while(x>=10){
      ans++;
      x-=10;
    }
    if(x>=5){
      ans++;
      x-=5;
    }
    ans+=x;
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	// your code goes here
	int n;
	while(cin >> n && n!=0){
		n=1000-n;
		int sum=0;
		int coin[]={500,100,50,10,5,1};
		for(int i=0;i<6;i++)
			while(n>=coin[i]){
				sum++;
				n-=coin[i];
			}
	cout << sum << endl;
	}
	return 0;
}

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