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<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(n,a) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

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

void f(int n){
  int k = 1000-n;
  cout<<dp[k]<<endl;
}

int main(){
  int n;
  fill(dp,dp+1100,inf);
  dp[0]=0;
  rep(i,1100){
    rep(j,6){
      if(i-a[j]<0) continue;
      dp[i]=min(dp[i],dp[i-a[j]]+1);
    }
  }
  while(1){
    cin>>n;
    if(n==0) break;
    f(n);
  }
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  
  cin >> money;
  oturi = 1000 - money;
  for(int i = 1000;oturi > 0;i /= 10){
    oturi %= i;
    if(oturi >= i/10){
      (oturi / (i/10) >= 5) ? (maisu += oturi / (i/10) - 4) : (maisu += oturi / (i/10));
    }
  }
  cout << maisu << endl;
    
    return 0;
  }

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    while (cin >> n && n) {
        int t = 1000 - n, ans = 0;
        ans += t / 500;
        t %= 500;
        ans += t / 100;
        t %= 100;
        ans += t / 50;
        t %= 50;
        ans += t / 10;
        t %= 10;
        ans += t / 5;
        t %= 5;
        ans += t;
        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int t[]={500,100,50,10,5,1};
	int n,cnt=0;
	while(cin>>n,n){
	cnt=0;
	n=1000-n;
	for(int i=0;i<6;i++){
	while(t[i]<=n)n-=t[i],cnt++;
	}
	cout<<cnt<<endl;
	}
	return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        n = 1000 - n;
        int ans = n/500+n%500/100+
            n%100/50+n%50/10+
            n%10/5+ n%5;
        cout << ans << endl;
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int x,a,b,c,d,e,f,g,h,i,j;
	scanf("%d %d %d %d %d %d %d %d %d %d",&x,&a,&b,&c,&d,&e,&f,&g,&h,&i);
	j=x-(a+b+c+d+e+f+g+h+i);
	printf("%d\n",j);
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a;
	cin >> a;
	if (a == 0)
	{

	}
	else
	{
		int b = 0;
		a = 1000 - a;
		for (; a != 0;)
		{
			if (a >= 500)
			{
				a = a - 500;
				b++;
			}
			else if (a >= 100)
			{
				a = a - 100;
				b++;
			}
			else if (a >= 50)
			{
				a = a - 50;
				b++;
			}
			else if (a >= 10)
			{
				a = a - 10;
				b++;
			}
			else if (a >= 5)
			{
				a = a - 5;
				b++;
			}
			else if (a >= 1)
			{
				a = a - 1;
				b++;
			}
		}
		cout << b << endl;
	}
	return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        n = 1000 - n
        int ans = n/500+n%500/100+
            n%100/50+n%50/10
            n%10/5+ n%5
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	if (price != 0)
	{
		while (oturi > 0)
		{
			if (oturi >= 500)
			{
				count++;
				oturi -= 500;
			}
			else if (oturi >= 100)
			{
				count++;
				oturi -= 100;
			}
			else if (oturi >= 50)
			{
				count++;
				oturi -= 50;
			}
			else if (oturi >= 10)
			{
				count++;
				oturi -= 10;
			}
			else if (oturi >= 5)
			{
				count++;
				oturi -= 5;
			}
			else if (oturi >= 1)
			{
				count++;
				oturi -= 1;
			}
		}	
	}

	cout << count << endl;

	getchar;
	getchar;
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	price=1000-price;
	while(1){
		if(flag==1){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	if(coin!=0){
	cout<<coin<<endl;
	}
	return 0;

}

C++: #include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>

using namespace std;

int main() {

  const array<int, 6> coins = { 500, 100, 50, 10, 5, 1 };

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

    n = 1000 - n;
    int count = 0;
    for ( auto coin : coins ) {
      if ( n >= coin ) {
    	count += (n / coin);
    	n %= coin;
      }
    }
    cout << count << endl;
  }
  return 0;  
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int co = 0;
		int a = 0;
		cin >> a;
		if (a == 0)
		{
			break;
		}
		
		int o = 0;
		o = 1000 - a;
		
		if (o >= 500)
		{
			co++;
			o -= 500;
		}
		else if (o >= 100)
		{
			co++;
			o -= 100;
		}
		else if (o >= 50)
		{
			co++;
			o -= 50;
		}
		else if (o >= 10)
		{
			co++;
			o -= 10;
		}
		else if (o >= 5)
		{
			co++;
			o -= 5;
		}
		else if (o >= 1)
		{
			co++;
			o -= 1;
		}
		
		cout << co << endl;
	}
}

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	while (1){
		cin >> a;
		if (a == 0){ break; }
		c = 0;
		a = 1000 - a;
		b = a;
		b = a / 500;
		c = c + b;
		a = a % 500;
		b = a / 100;
		c = c + b;
		a = a % 100;
		b = a / 50;
		c = c + b;
		a = a % 50;
		b = a / 10;
		c = c + b;
		a = a % 10;
		b = a / 5;
		c = c + b;
		a = a % 5;
		b = a;
		c = c + b;
		cout << c << endl;
		a = 0;
		b = 0;
		c = 0;
	}
	return 0;
}