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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

//

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

int main() {

    while(true) {
        int price; cin >> price;
        if (price == 0) break;
        int change = 1000-price;
        int cnt = 0;

        for (int c : coins) {
            int v = change / c;
            cnt += v;
            change -= (v*c);
        }

        cout << cnt << endl;

    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;
int main(){
	int i=0,a,b,c,d,e,f,g,ans;
	while(i<5){
		cin>>a;
		if(a==0)break;
		b=1000-a;
		c=b%500;
		d=c%100;
		e=d%50;
		f=e%10;
		g=f%5;
		ans=b/500+c/100+d/50+e/10+f/5+g;
		cout<<ans<<endl;
		ans=0;
		i++;
	}
	return 0;
}

C++: #include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=50){
		i++;
		n=(n-50);
	}
	if (n>=10){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=6){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, now, count;
  while(1){
    cin >> n;
    now = 0;
    count = 0;
    if(n==0) break;
    
    while(1){
      if(1000-n-now >= 500){
        now += 500;
        count++;
      } else if (1000-n-now >= 100){
        now += 100;
        count++;
      } else if (1000-n-now >= 50){
        now += 50;
        count++;
      } else if (1000-n-now >= 10){
        now += 10;
        count++;
      } else if (1000-n-now >= 5){
        now += 5;
        count++;
      } else {
        now += 1;
        count++;
      }

      if(1000-n-now == 0) {
        cout << count << endl;
        break;
      }
    }
  }

  return 0;
}

C++: #include<stdio.h>

int main(){
	const int CASH = 1000;
	int price;
	int hundred;
	int ten;
	int digit;
	int count;

	while( 1 ) {

		count = 0;

		scanf( "%d",&price );
		if( !price ) break;

		price = CASH - price;

		hundred = price / 100;
		ten = ( price - hundred * 100 ) / 10;
		digit = price - ( hundred * 100 ) - (ten * 10);

		while( hundred > 0 ){
			if( hundred >= 5 ){
				hundred -= 5;
				count++;
			}else{
				hundred--;
				count++;
			}
		}

		while( ten > 0 ){
			if( ten >= 5 ){
				ten -= 5;
				count++;
			}else{
				ten--;
				count++;
			}
		}

		while( digit > 0 ){
			if( digit >= 5 ){
				digit -= 5;
				count++;
			}else{
				digit--;
				count++;
			}
		}

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

	}
	return 0;
}

C++: // AOJ 0521
#include<cstdio>
#define rep(i,a) for( int i = 0; i != (a); ++i )

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

int main()
{
	int p;
	scanf( "%d", &p );
	p = 1000-p;

	int ans = 0;
	rep( i, 6 )
		ans += p/C[i], p %= C[i];

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

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;

	while( n <= 500 ){
		n = n-500;
		m++;
	}
	while( n <= 100 ){
		n = n-100;
		m++;
	}
	while( n <= 50 ){
		n = n-50;
		m++;
	}
	while( n <= 10 ){
		n = n-10;
		m++;
	}
	while( n <= 5 ){
		n = n-5;
		m++;
	}
	while( n <= 1){
		n = n-1;
		m++;
	}

	cout << m << endl;

	return 0;
}

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<stdio.h>
int main(void)
{
	int n,s,ss,z,z1,z2,z3,z4;
	scanf("%d",&n);
	while(n!=0){
	ss=1000-n;
	s=ss/500;
	z=ss%500;
	s+=z/100;
	z1=z%100;
	s+=z1/50;
	z2=z1%50;
	s+=z2/10;
	z3=z2%10;
	s+=z3/5;
	z4=z3%5;
	s+=z4/1;	
	printf("%d\n",s);
	scanf("%d",&n);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n;
	int money[6] = {500,100,50,10,5,1};
	while(cin >> n, n){
		
		int change = 0;
		n = 1000 - n;
		rep(i,6){
			
			change += n / money[i];
			n = n % money[i];
		}
		cout << change << endl;
	}

	return 0;
}