Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}

C++: #include<iostream>
using namespace std;
int t[] = {500,100,50,10,5,1};
int main(void){
    while(true){
        int n,count = 0;
        cin >> n;
        if(n == 0)break;
        n = 1000 - n;
        for(int i=0; i<6; i++){
            count+=n/t[i];
            n%=t[i];
        }
        cout<<count<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main() {
	int a, b[] = { 500,100,50,10,5,1 }, ruio = 0;
	cin >> a;
	while (a != 0) {
		a = 1000 - a;
		for (int i = 0; i < 5; i++) {
			ruio += a / b[i];
			a = a%b[i];
		}
		cout << ruio+a << endl;
		cin >> a;
		ruio = 0;
	}
}

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

int main(){
  int m;
  while(cin >> m,m){
    int c=0;
    m=1000-m;
	while(m-500>=0){
	  m=m-500;
	  c++;
	}
	while(m-100>=0){
	  m=m-100;
	  c++;
	}
	while(m-50>=0){
	  m=m-50;
	  c++;
	}
	while(m-10>=0){
	  m=m-10;
	  c++;
	}
	while(m-5>=0){
	  m=m-5;
	  c++;
	}
	while(m-1>=0){
	  m=m-1;
	  c++;
	}
	cout << c << endl;
  }
  return 0;
}

C++: #include <cstdio>
using namespace std;
const int coin[] = {500,100,50,10,5,1};
int main() {
	int n;
	while (scanf("%d",&n)&&n!=0) {
		int res=0,turi=1000-n,m=0;
		while (turi!=0) {
			if (turi<coin[m]) {
				m++;
			} else {
				turi -= coin[m];
				res++;
			}
		}
		printf("%d\n",res);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <utility>
using namespace std;
int main() {
	int N;
	int C[]={500,100,50,10,5,1};
	while(scanf("%d",&N),N) {
		N=1000-N;
		int sum=0;
		for(int i=0;i<6;i++) {
			sum+=N/C[i];
			N%=C[i];
		}
		printf("%d\n",sum);
	}
}

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

int main(){
  int n;
  while(cin>>n,n!=0){
    n = 1000-n;
    const vector<int> list = {500,100,50,10,5,1};
    int ans = 0;
    for(int i=0;i<list.size();i++){
      ans += n / list[i];
      n = n % list[i];
    }
    cout<<ans<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
	int cut=0;
	int a;
	int b;
	while(1){
	cin>>a;
		cut=0;
		if(a==0){
			break;
		}
	b=1000-a;
	cut+=b/500;
	b=b%500;
	cut+=b/100;
	b=b%100;
	cut+=b/50;
	b=b%50;
	cut+=b/10;
	b=b%10;
	cut+=b/5;
	b=b%5;
	cut+=b;
	cout<<cut<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,i,j,m,a=0;
  while(1){
    a=0;
    cin >> n;
    if(n==0)break;
    m=1000-n;
    while(m>0){
      if(m%500==0){
	a++;
	m=m-500;
      }
      else if(m%100==0){
	a++;
	m=m-100;
      }
      else if(m%50==0){
	a++;
	m=m-50;
      }
      else if(m%10==0){
	a++;
	m=m-10;
      }
      else if(m%5==0){
	a++;
	m=m-5;
      }
      else if(m%1==0){
	a++;
	m=m-1;
      }
    }
    cout << a << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "\n";
 
    
    }
    return 0;

}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(n!=0){b=1000-a;
c=0;
if(b>=500){b=b-500; c=c+1;}
if(b>=100){while(b<100){b=b-100; c=c+1;}}
if(b>=50){b=b-50; c=c+1;}
if(b>=10){while(b<10){b=b-10; c=c+1;}}
if(b>=5){b=b-5; c=c+1;}
c=b+c;
cout << c<<endl;
}
}
}

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

int main() {
	int n,a,i=0;
	cin>>n;
	a=1000-n;
	if(a>=500){
		i+=1;
		a-=500;
	}
	if(a>=100){
		int b=a/100;
		i+=b;
		a-=100*b;
	}
	if(a>=50){
		i+=1;
		a-=50;
	}
	if(a>=10){
		int b=a/10;
		i+=b;
		a-=10*b;
	}
	if(a>=5){
		i+=1;
		a-=5;
	}
	if(a>=1)
		i+=a;
	cout<<i<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int ans = 0;
        n = 1000 - n;
        for (auto & i : {500, 100, 50, 10, 5, 1}) {
            ans += n / i, n -= i * (n / i);
        }
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

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

int main()
{
  cin >> n;
  n = 1000 - n;

  int res = 0;
  rep(k, 6){
    res += n / coin[k];
    n -= n / coin[k] * coin[k];
  }

  cout << res << endl;

  return 0;
}

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

ll N;

ll solve(ll N) {
  ll M=1000-N;
  ll ans=0;
  ll a=M/500;
  M-=a*500;
  ll b=M/100;
  M-=b*100;
  ll c=M/50;
  M-=c*50;
  ll d=M/10;
  M-=d*10;
  ll e=M/5;
  M-=e*5;
  return a+b+c+d+e+M;
}
  

int main() {
  while(cin>>N) {
    if (N) cout<<solve(N)<<endl;
    else break;
  }
  return 0;
}

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

int main(){
	int price,count,x,n;
	int coin[] = {500,100,50,10,5,1};
	while(cin >> n){
		price = 1000 - n;
		count = 0;
		for(int i = 0;i<6;i++){
			x = price / coin[i];
			count += x;
			price -= coin[i] * x; 
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

int main(){

  while(1){


  int ans = 0;

  int n;

  scanf("%d",&n);

  if(n == 0) break;

  n = 1000 - n;

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

  for(int i = 0;i < 6;i++){
    if(n == 0) break;
    ans += n / k[i];
    n = n % k[i];
  }

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

  }

  return 0;

}