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>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<iostream>
using namespace std;
int main(){
  int money;
  int change;
  while(cin >> money,money){
  money=1000-money;
  change=0;
  while(money){
    if(money>=500){
      change++;
      money-=500;
    }
    else if(money>=100){
      change++;
      money-=100;
    }
    else if(money>=50){
      change++;
      money-=50;
    }
    else if(money>=10){
      change++;
      money-=10;
    }
    else if(money>=5){
      change++;
      money-=5;
    }else{
      change++;
      money-=1;
    }
  }
  cout << change << endl;
}
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0, coin = { 500,100,50,10,5 };

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << 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;


	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    int in;
    while(1){
        int cnt=0;
        cin >> in;
        if(in==0)break;
        in = 1000-in;
        if(in>=500){
            cnt++;
            in-=500;
        }
        if(in>=100){
            cnt+=in/100;
            in=in%100;
        }
        if(in>=50){
            cnt++;
            in-=50;
        }
        if(in>=10){
            cnt+=in/10;
            in=in%10;
        }
        if(in>=5){
            cnt++;
            in-=5;
        }
        cnt+=in;
        cout << cnt <<endl;
    }
    
    return 0;
}

C++:  #include <functional>
 #include <algorithm>
 #include <iostream>
 #include <numeric>
 #include <iomanip>
 #include <utility>
 #include <cstdlib>
 #include <sstream>
 #include <bitset>
 #include <vector>
 #include <cstdio>
 #include <ctime>
 #include <queue>
 #include <deque>
 #include <cmath>
 #include <stack>
 #include <list>
 #include <map>
 #include <set>
 
 using namespace std;
 
 typedef vector<int> VI;
 typedef pair<int,int> pii;
 typedef long long ll;
 
 #define dump(x)  cerr << #x << " = " << (x) << endl
 #define rep(i,n) for(int i=0;i<(n);i++)
 #define ALL(a)  (a).begin(),(a).end()
 #define PB push_back
 #define sz size()
 
 const double EPS = 1e-10;
 const int INF = 100000000;
 
 int solve(int n){
 int ret=0;
 int m[]={500,100,50,10,5,1};
 rep(i,6){
 ret+=n/m[i];
 n-=m[i]*(n/m[i]);
 }
 return ret;
 }
 
 
 int main(){
 int n;
 while(cin>>n){
 if(n==0)break;
 cout<<solve(1000-n)<<endl;;
 }
 
 return 0;
 }

C++: #include<iostream>

using namespace std;

int main(){
	int input;//テ・ツ?・テ・ツ環崚ァツ板ィ
	int en[] = {500,100,50,10,5,1};//テァツ。ツャティツイツィテ」ツ?ョテァツィツョテゥツ。ツ?
	
	while(1){
		cin >> input;//テ・ツ?・テ・ツ環?
		
		if(input == 0) break;
		
		int cnt=0;
		int oturi=1000-input;
		
		for(int i=0;i<6;i++){
			cnt+=oturi/en[i];
			oturi=oturi%en[i];
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


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

C++: #include <stdio.h>

int main(void) {
	int n, i,cou, list[6] = {500, 100, 50, 10, 5, 1};
	
	while(scanf("%d", &n)){
		if(n == 0) break;
		cou = 0;
	n = 1000 - n;
	for( i = 0; 6 > i; i++){
		cou += n/list[i];
		n %= list[i];
		
		if(n == 0) break;
	}
	printf("%d\n", cou);
	}
	return 0;
}

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

int main(){
	int C[6] = {500, 100, 50, 10, 5, 1};	// 0:500円 1:100円 2:50円 3:10円 4:5円 5:1円
	int price;
	int change = 1000;
	int coin = 0;
	
	for(;;){
		change = 1000;
		coin = 0;
		cin >> price;
		if(price == 0)	break;
		change -= price;
	
		for(int i = 0; i < 6; i++){
			coin += change / C[i];
			change %= C[i];
		}
	
		cout << coin;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int count(int x, int c){
   if(x >= 500){
       return count(x-500, c+1);
   }
   if(x >= 100){
       return count(x-100, c+1);
   }
   if(x >= 50){
       return count(x-50, c+1);
   }
   if(x >= 10){
       return count(x-10, c+1);
   }
   if(x >= 5){
       return count(x-5, c+1);
   }
   if(x == 0){
       return c;
   }
   else {
       return count(x-1,c+1);
   }
}

int main (void){
   int x;
   while (true){
       cin >> x;
       if(x == 0) {
           break;
       }
       cout << count(1000 - x, 0) << endl;
   }
}

C++: #include<stdio.h>
int main(void) {
	int cost, coin, cv[] = { 500,100,50,10,5,1 };
	while (scanf("%d", &cost))
	{
		if (cost == 0)break;
		coin = 0;
		cost = 1000 - cost;
		for (int i = 0; i < 6; i++)
		{
			coin += cost / cv[i];
			cost = cost % cv[i];
		}
		printf("%d\n", coin);
	}
	return 0;
}

C++: #include <stdio.h>
using namespace std;

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
}