Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

C++: #include<stdio.h>
int main(void)
{
	int gohyaku,hyaku,gozyu,zyu,go,ichi;
	int dai,otsuri,mai;
	while(scanf("%d",&dai)!=EOF){
		otsuri=1000-dai;
		gohyaku=0;
		hyaku=0;
		gozyu=0;
		zyu=0;
		go=0;
		ichi=0;
		while(otsuri>=500){
			otsuri=otsuri-500;
				gohyaku++;
		}
		while(otsuri>=100){
			otsuri=otsuri-100;
				hyaku++;
		}
		while(otsuri>=50){
			otsuri=otsuri-50;
				gozyu++;
		}
		while(otsuri>=10){
			otsuri=otsuri-10;
				zyu++;
		}
		while(otsuri>=5){
			otsuri=otsuri-5;
				go++;
		}
		while(otsuri>=1){
			otsuri=otsuri-1;
				ichi++;
		}
		mai=gohyaku+hyaku+gozyu+zyu+go+ichi;
		printf("%d\n",mai);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
	int n[1000],i=0,cnt=0,j;
	while(1){
		cin>>n[i];
		if(n[i]==0) break;
		n[i]=1000-n[i];
		if(n[i]>=500){n[i]-=500; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=100){n[i]-=100; cnt+=1;}}
		if(n[i]>=50){n[i]-=50; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=10){n[i]-=10; cnt+=1;}}
		if(n[i]>=5){n[i]-=5; cnt+=1;}
		for(j=0;j<4;j++){if(n[i]>=1){n[i]-=1; cnt+=1;}}
		i+=1;
		cout<<cnt<<endl;
		cnt=0;
	}
	return 0;
}

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

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

C++: #include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main() {
	while (true) {
		int coin = 0;
		int price = 0;

		cin >> price;
		if (price == 0) {
			break;
		}

		price = 1000 - price;

		for (auto temp : { 500, 100, 50, 10, 5, 1 }) {
			const auto temp_div = div(price, temp);
			coin += temp_div.quot;
			price = temp_div.rem;
		}

		cout << coin << endl;
	}
	return 0;
}

C++: #include<cstdio>

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

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

int main(){
  while(true) if(solve()) return 0;
}

C++: //============================================================================
// Name        : 0521.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

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

	}
	cout <<ans<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);   

    int n;
    while(cin >> n){
        if(!n) break;

        int m = 1000 - n;
        int ans = 0;

        rep(i,6){
            ans += m/coin[i];
            m = m%coin[i];
        }

        cout << ans << endl;
    }

    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	int price;
	cin >> price;

	int change = 1000 - price;
	int ans = 0;

	for(int i = 0; i < 6; ++i) {
		while(change >= coins[i]) {
			change -= coins[i];
			++ans;
		}
	}

	cout << ans << endl;		

	return EXIT_SUCCESS;
}

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 <stdio.h>

int main(void)
{
	int num;
	int ans;
	int price;
	
	while (1){
		scanf("%d", &price);
		
		if (price == 0)break;
		
		price = 1000 - price;
		
		ans = 0;
		while (price){
			if (price - 500 >= 0){
				price -= 500;
				ans++;
			}
			else if (price - 100 >= 0){
				price -= 100;
				ans++;
			}
			else if (price - 50 >= 0){
				price -= 50;
				ans++;
			}
			else if (price - 10 >= 0){
				price -= 10;
				ans++;
			}
			else if (price - 5 >= 0){
				price -= 5;
				ans++;
			}
			else if (price - 1 >= 0){
				price -= 1;
				ans++;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int dp[1005];
int c[6] = {1, 5, 10, 50, 100, 500};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int x;
  fill(dp, dp + 1005, 0x3f3f3f3f);
  dp[0] = 0;
  for (int i = 1; i <= 1000; i++) {
    for (int j = 0; j < 6; j++) {
      if (i - c[j] >= 0)
        dp[i] = min(dp[i], dp[i - c[j]] + 1);
    }
  }
  while (true) {
    cin >> x;
    if (x == 0)
      break;
    x = 1000 - x;
    cout << dp[x] << endl;
  }
}

C++: #include <iostream>

int main() {
	int a = 0,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;

	return 0;


}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int sum=0;
    int x;
    int cnt=0;
    while(1){
        cin>>x;
        if(!x)
            return 0;
        sum=1000-x;
        while(sum>0){
            if(sum>=500){
                cnt++;
                sum-=500;
            }
            else if(sum>=100){
                cnt++;
                sum-=100;
            }
            else if(sum>=50){
                cnt++;
                sum-=50;
            }
            else if(sum>=10){
                cnt++;
                sum-=10;
            }
            else if(sum>=5){
                cnt++;
                sum-=5;
            }
            else{
                cnt++;
                sum-=1;
            }
        }
        cout<<cnt<<endl;
        cnt=0;
    }


    return 0;
}