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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

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

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, ans;
   while (cin >> n, n) {
      n = 1000 - n, ans = 0;
      for (int i = 0; i < 6; i++) {
         ans += n / t[i];
         n %= t[i];
      }
      cout << ans << endl;
   }
   return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int money=1000, price;
	int coin[6] = {500,100,50,10,5,1};
	int count,sum=0;
	cin >> price;
	money-=price;
	for(int i=0; i<6; i++){
		count=0;
		if(money >= coin[i]){
			count+=money/coin[i];
			money-=coin[i]*count;
		}
		sum+=count;
	}
	cout << sum << endl;
}

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

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

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

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/

	//おつり
	while(true){
		int N;
		if(N == 0) break;
		
		int nedan;
		cin >> nedan;
		int oturi = 1000-nedan;
		int onum= 0;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		cout << onum << endl;

	}

	return 0;
}

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++)
#define downto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i >= _##i; i--)
#define downtil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

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

    loop {
        int N = 1000 - next<int>(), ans = 0;
        if(N == 1000) break;

        for(int coin : {500, 100, 50, 10, 5, 1}) {
            ans += N / coin;
            N %= coin;
        }

        cout << ans ln;
    }

    return 0;
}

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

int main() {
  int n;
  while(cin >> n&&n!=0){
  int ans=0;
  n=1000-n;
  vector<int> c={500,100,50,10,5,1};
  r(i,6){
    int t=n/c[i];
    n-=t*c[i];
    ans+=t;
  }
  cout<<ans<<endl;
  }
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	int coin[10],price,sum;
	while(cin>>price,price){
		for(int i=0;i<10;i++){
			coin[i]=0;
		}
		sum=0;
		price=1000-price;
		if(price/500){
			coin[0]=(price/500);
			price=price-500*coin[0];
		}
		if(price/100){
			coin[1]=(price/100);
			price=price-100*coin[1];
		}
		if(price/50){
			coin[2]=(price/50);
			price=price-50*coin[2];
		}
		if(price/10){
			coin[3]=(price/10);
			price=price-10*coin[3];
		}
		if(price/5){
			coin[4]=(price/5);
			price=price-5*coin[4];
		}
		if(price/1){
			coin[5]=(price/1);
			price=price-coin[5];
		}
		for(int i=0;i<5;i++){
			sum=sum+coin[i];
		}
		cout<<sum<<endl;
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
int main()
{
	int t=0,yen,put=0,coin[6]={500,100,50,10,5,1};
	scanf("%d",&yen);
	yen=abs(1000-yen);
	for(int i=0;i<6;i++,t=0)
	{
		t=yen/coin[i];
		put+=t;
		yen-=t*coin[i];
	}
	printf("%d\n",put);
	//Sleep(1000);
}