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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
    int n;
    while(cin>>n,n){
        n=1000-n;
        vint v={500,100,50,10,5,1};
        int ans=0;
        rep(i,v.size()){
            while(n>=v[i]){
                ans++;
                n-=v[i];
            }
        }
        cout<<ans<<endl;
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
      cout<<fixed<<setprecision(20);
    mainmain();
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<61)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  int C[] = {500, 100, 50, 10, 5, 1};
  while (cin >> N, N) {
    int rem = 1000 - N;
    int ans = 0;
    int i = 0;
    while (rem)  {
      if (rem >= C[i]) {
        ans += rem / C[i];
        rem -= (rem / C[i]) * C[i];
      }
      i += 1;
    }
    cout << ans << endl;
  }
  return 0; 
}

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

using ll = long long;
using namespace std;

int main() {
    array<int, 1001> A{};
    fill(A.begin(), A.end(), 10000);
    A[0] = 0;
    int a[6] = {500, 100, 50, 10, 5, 1};
    for (int i = 0; i < 1001; ++i) {
        for (auto &&v : a) {
            if (v <= i) {
                A[i] = min(A[i-v]+1, A[i]);
                break;
            }
        }
    }
    int n;
    while(cin>>n, n) {
        cout << A[1000 - n] << "\n";
    }
    return 0;
}

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


int main(){
  while(true){
    int much;
    int ot=0;
    cin>>much;
    if(much==0){
      break;
    }
    much=1000-much;
    while(true){
      if(much>=500){
	much=much-500;
	ot=ot+1;
      }else{
	break;
      }
    }
    while(true){
      if(much>=100){
	much=much-100;
	ot=ot+1;
      }else{
	break;
      }
    }
    while(true){
      if(much>=50){
	much=much-50;
	ot=ot+1;
      }else{
	break;
      }
    }
    while(true){
      if(much>=10){
	much=much-10;
	ot=ot+1;
      }else{
	break;
      }
    }
    while(true){
      if(much>=5){
	much=much-5;
	ot=ot+1;
      }else{
	break;
      }
    }
    while(true){
      if(much>=1){
	much=much-1;
	ot=ot+1;
      }else{
	break;
      }
    }
    cout<<ot<<endl;
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){

  while(1) {

  int price;
  cin >> price;
  if (price == 0) break;
  int otsuri = 1000 - price;
  int nCoin = 0;
  nCoin += otsuri/500;
    otsuri = otsuri % 500;

  nCoin += otsuri/100;
  otsuri = otsuri % 100;

  nCoin += otsuri/50;
  otsuri = otsuri % 50;

  nCoin += otsuri/10;
  otsuri = otsuri % 10;

    nCoin += otsuri/5;
  otsuri = otsuri % 5;
  nCoin += otsuri;

  cout << nCoin << endl;
}

    }

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

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0, coin = { 500,100,50,10,5 };

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	if (price != 0)
	{
		while (oturi > 0)
		{
			if (oturi >= 500)
			{
				count++;
				oturi -= 500;
			}
			else if (oturi >= 100)
			{
				count++;
				oturi -= 100;
			}
			else if (oturi >= 50)
			{
				count++;
				oturi -= 50;
			}
			else if (oturi >= 10)
			{
				count++;
				oturi -= 10;
			}
			else if (oturi >= 5)
			{
				count++;
				oturi -= 5;
			}
			else if (oturi >= 1)
			{
				count++;
				oturi -= 1;
			}
		}	
	}

	cout << count << endl;


	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    int in;
    while(1){
        int cnt=0;
        cin >> in;
        if(in==0)break;
        in = 1000-in;
        if(in>=500){
            cnt++;
            in-=500;
        }
        if(in>=100){
            cnt+=in/100;
            in=in%100;
        }
        if(in>=50){
            cnt++;
            in-=50;
        }
        if(in>=10){
            cnt+=in/10;
            in=in%10;
        }
        if(in>=5){
            cnt++;
            in-=5;
        }
        cnt+=in;
        cout << cnt <<endl;
    }
    
    return 0;
}