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 <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	if(n>=500){
		n = n%500;
		m = n/500;
	}
	if(n>=100){
		n = n%100;
		m = m+n/100;
	}
	if(n>=50){
		n = n%50;
		m = m+n/50;
	}
	if(n>=10){
		n = n%10;
		m = m+n/10;
	}
	if(n>=5){
		n = n%5;
		m = m+n/5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

	return 0;
}

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

int main() {
    while (true) {
        int input;
        cin >> input;
        if (input == 0) {
            break;
        }
        int change = 1000 - input;
        int coin = 0;
        while (change > 0) {
            if (change >= 500) {
                change -= 500;
            } else if (change >= 100) {
                change -= 100;
            } else if (change >= 50) {
                change -= 50;
            } else if (change >= 10) {
                change -= 10;
            } else if (change >= 5) {
                change -= 5;
            } else {
                change--;
            }
            coin++;
        }
        cout << coin << endl;
    }
}

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

int main()
{
int m;
while(cin>>m){
if(m==0) break;
int ans=0;
m=1000-m;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans<<endl;

}

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int n, k;
int main(){
    while(cin >> n, n){
        int res=0;
        int rest=1000-n;
        while(rest){
            if(rest-500>=0){
                res++;
                rest-=500;
                continue;
            }
            if(rest-100>=0){
                res++;
                rest -=100;
                continue;
            }
            if(rest-50>=0){
                res++;
                rest -=50;
                continue;
            }
            if(rest-10>=0){
                res++;
                rest -=10;
                continue;
            }
            if(rest-5>=0){
                res++;
                rest -=5;
                continue;
            }
            if(rest-1>=0){
                res++;
                rest -=1;
                continue;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,s,ss;
	while(1){
		scanf("%d",&a);
		if(a==0)break;
		s=1000-a;
		ss=s/500;
		s=s%500;
		ss+=s/100;
		s=s%100;
		ss+=s/50;
		s=s%50;
		ss+=s/10;
		s=s%10;
		ss+=s/5;
		s=s%5;
		ss+=s/1;
		printf("%d\n",ss);
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int coin[6] = {500,100,50,10,5,1};
	while(1){
		int in;
		cin>> in;
		if(!in) break;
		int ans=0;
		in = 1000 - in;
		for(int i=0;i<6;i++){
			int c = coin[i];
			ans += in / c;
			in = in - c*(in/c);
		}
//		assert(in==0);
		cout<< ans<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include<stdio.h>
int main (void)
{
	int n;
	int s;
	int cnt;
	
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		s=1000-n;
		while(s>=500){
			s=s-500;
			cnt++;
		}
		while(s>=100){
			s=s-100;
			cnt++;
		}
		while(s>=50){
			s=s-50;
			cnt++;
		}
		while(s>=10){
			s=s-10;
			cnt++;
		}
		while(s>=5){
			s=s-5;
			cnt++;
		}
		while(s>=1){
			s=s-1;
			cnt++;
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        int tmp = 1000-n;

        int ans = 0;
        int money[] = {500, 100, 50, 10, 5, 1};
        rep(i, 6) {
            ans += tmp/money[i];
            tmp -= money[i]*(tmp/money[i]);
        }
        cout << ans << '\n';
    }
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

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

    while(true) {
	cin>>n;
	if(n==0) break;
	n=1000-n;
	int ans=0;
	REP(i,6) {
		if(n>=a[i]) {
			int tmp=n/a[i];
			ans+=tmp;
			n-=tmp*a[i];
		}
	}
	cout<<ans<<endl;
    }

	return 0;
}

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

int main() {
	int a,b=0;
	while(1){
		cin >> a;
		if(a==0) break;
		a=1000-a;
		if(a>500){
			a-=500;
			b++;
		}
	
		while(1){
			if(a<100) break;
			a-=100;
			b++;
		}

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

int gcd(int a, int b){return b?gcd(b, a % b):a;}
/*-------------------------------*/

int main(void)
{
  int list[6] = {500, 100, 50, 10, 5, 1};
  int n;
  int cnt;

  while (true){
    cin >> n;
    if (n == 0) break;
    n = 1000 - n;
    cnt = 0;
    REP(i, 6){
      if (i % 2 == 0){
        if (n - list[i] >= 0){
          cnt++;
          n -= list[i];
        }
      }
      else{
        if (n / list[i] != 0){
          cnt += n / list[i];
          n -= (n / list[i]) * list[i];
        }
      }
    }
    cout << cnt << endl;
  }
}