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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, money, change;
  int coin[6] = {500, 100, 50, 10, 5, 1};

  while(1) {
    cin >> money;
    if(!money) break;

    change = 1000-money;

    int cnt = 0;
    REP(i, 6) {
      while(change/coin[i] > 0) {	
	cnt++;
	change -= coin[i];
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;


int main(){

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

	while(true){
		scanf("%d",&price);
		if(price == 0)break;

		sum = 0;

		price = 1000 - price;

		for(int i = 0; i <= 5; i++){
			while(price >= coin[i]){
				price -= coin[i];
				sum++;
			}
		}

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

    return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num = 0;
	
	scanf("%d", &price);
	back = PAY - price;
	
	for (int i=0; i<COINNUM; i++){
		while (back >= coins[i]){
			num++;
			back -= coins[i];
//			printf("%d, ", coins[i]);
		}
	}
	printf("%d", num);
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <string.h>

using namespace std;

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

int main(){
  	cin >> k[0];
    for(int i = 1; k[i-1]; i++){
        cin >> k[i];
      	k[i-1] = 1000 -k[i-1];
      	amt++;
    }

    for(int i = 0; k[i]; i++){
        for(int j = 0; j < 6; j++){
            while(k[i] - coins[j] >= 0){
                k[i] -= coins[j];
                cnt[i]++;
            }
        }
    } 

    for(int i = 0; i < amt; i++){
        cout << cnt[i] <<  endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int mone,A,A1;
    cin>>mone;
    A=1000-mone;
    A1=A%500;
    A=A/500+A1/100+A1%100/50+A1%100%50/10+A1%100%50%10/5+A1%100%50%10%5;
    cout<<A<<"\n";
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        if (a[i] == 0) break;
        
        int count = 0;
        int n = 1000-a[i];
        
        count += (n - n % 500) / 500;
        count += (n - n % 100) / 100;
        count += (n - n % 50) / 50;
        count += (n - n % 10) / 10;
        count += (n - n % 5) / 5;
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<int> ans;
  int coin[6] = {500, 100, 50, 10, 5, 1};
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;

    int oturi = 1000 - n;
    int res = 0;
    rep(i,6) {
      if (oturi == 0) break;
      if (oturi < coin[i]) continue;
      res += oturi / coin[i];
      oturi = oturi % coin[i];
    }
    ans.push_back(res);
  }
  rep(i,ans.size()) cout << ans[i] << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){

	while(1){
		int a; cin >> a;
		if(a == 0) return 0;
		a = 1000 - a;

		int ans = 0;

		ans += a/500;
		a %= 500;
		ans += a/100;
		a %= 100;
		ans += a/50;
		a %= 50;
		ans += a/10;
		a %= 10;
		ans += a/5;
		a %= 5;
		ans += a;

		cout << ans << endl;
	}

}