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 main(){
    int a;
    while(cin>>a){
        if(a==0)return 0;
    int b=1000-a;
    int count=0;
    if(b/500==1){
        b=b-500;
        count++;
    }
    if(b/100!=0){
            int c=b/100;
            count+=c;
            b=b-100*c;
        }
    if(b/50==1){
            b=b-50;
            count++;
        }
     if(b/10!=0){
            int d=b/10;
            count+=d;
            b=b-10*d;
        }
     if(b/5==1){
            b=b-5;
            count++;
        }
    count+=b%5;
    cout<<count<<endl;
    }
}

C++: #include <stdio.h>

int N;
int coin[6] = { 500,100,50,10,5,1 };
int ans = 0;

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
	}
	printf("%d\n", ans);
	return 0;
}

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


int main(){

  while(1){
    int n;
    cin >> n;
    if(n==0)break;
    n = 1000 - n;
    int ans=0;
    if(n >= 500){
      n -= 500;
      ans++;
    }
    while(n >= 100){
      n-=100;
      ans++;
    }
    if(n >= 50){
      n-=50;
      ans++;
    }
    while(n >= 10){
      n-=10;
      ans++;
    }
    if(n >= 5){
      n-=5;
      ans++;
    }
    ans += n;
 
  cout << ans <<endl;
  }


}

C++: #include <iostream>

using namespace std;

int main(){
  int money;
  while(cin >> money && money !=0){
    int count =0;
    int res = 1000 - money;
    for(int i=0;i<3;i++){
      //      cout << res << endl;
      count +=res %10;
      if(res % 10 >5){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}

C++: #include<iostream>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum;
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum << endl;
	
	return 0;
}

C++: //
//  main.cpp
//  hoge
//
//  Created by ???????????? on 2017/11/09.
//  Copyright ?? 2017??´ ????????????. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int d[5];
    for (int i=0; i<5; i++) {
        cin >> d[i];
    }
    
    for (int i=0; i<5; i++) {
        int n=1000-d[i],count=0;
        
        if(d[i] == 0) break;
        
        while (n % 5 == 0) {
            if(n % 500 == 0) {
                count++;
                n-=500;
                continue;
            }
            if(n % 100 == 0) {
                count++;
                n-=100;
                continue;
            }
            if(n % 50 == 0) {
                count++;
                n-=50;
                continue;
            }
            if(n % 10 == 0) {
                count++;
                n-=10;
                continue;
            }
            if(n % 5 == 0) {
                count++;
                n-=5;
                continue;
            }
        }
        count+=n;
        cout << n << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
int coins[] = { 500, 100, 50, 10, 5, 1 };

int main()
{
//	cut here before submit 
//	freopen ("testcase.change2", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int money;
		stringstream ss(str);
		ss >> money;
		
		if (money == 0 ){
			break;
		} // end if
		int change = 1000 - money;
		int res = 0;
		int i;

		for (i = 0; i < sizeof(coins)/sizeof(coins[0]); ++i) {
			while (change >= coins[i] ){
				change -= coins[i];
				++res;
			} // end while
		} // end for

		cout << res << endl;		
		
	} // end loop
		
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n,sum,box[]={500,100,50,10,5,1};
	while(cin>>n,n){
		n=1000-n;
		sum=0;
		for(int i=0;i<6;i++){
			sum+=n/box[i];
			n=n-n/box[i]*box[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num_answer = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

	}
	

	for (int i = 0; i < j;++i) {
		cost_return = 1000 - cost_input[i];
		num_answer = 0;

		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1)
		{
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}

		CO num_answer E
	}
}

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