Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <deque>
using namespace std;

int main()
{
	int money[100],pay[100],count[100] = {0},i = 0;

	while(1)
	{
		cin>>pay[i];
		if(pay[i] == 0)break;
		money[i] = 1000 - pay[i];

		while(money[i] >= 1)
		{
			if(money[i] >= 500)
			{
				money[i] -= 500;
				count[i]++;
			}
			else if(money[i] >= 100)
			{
				money[i] -= 100;
				count[i]++;
			}
			else if(money[i] >= 50)
			{
				money[i] -= 50;
				count[i]++;
			}
			else if(money[i] >= 10)
			{
				money[i] -= 10;
				count[i]++;
			}
			else if(money[i] >= 5)
			{
				money[i] -= 5;
				count[i]++;
			}
			else if(money[i] >= 1)
			{
				money[i] -= 1;
				count[i]++;
			}
		}
	i++;
	}
	for(int j=0; j<i; j++)
		cout<<count[j]<<endl;

	return 0;

}

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

int main() {
	int all, rem, count = 0, tmp;
	while (1) {
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
		return 0;
	}
	return 0;

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};
    int money = 1000;
    int count = 0;
    int i = 0;

    scanf("%d", &amount);

    money -= amount;

    while (i < 6){
        if (money - change[i] >= 0){
            money -= change[i];

            count++;
        }
        else {
            i++;
        }
    }

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

    return (0);
}

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

    }