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 price,cnt;
while(cin>>price){
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=(price%500);
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
}
return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
	cin>>a;
	b=(1000-a)/500;
	c=(1000-(a+500*b))/100;
	d=(1000-(a+500*b+100*c))/50;
	e=(1000-(a+500*b+100*c+50*d))/10;
	f=(1000-(a+500*b+100*c+50*d+10*e))/5;
	g=(1000-(a+500*b+100*c+50*d+10*e+5*f))/1;
	cout<<b+c+d+e+f+g<<endl;
	return 0;
}

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

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

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

int money,c[1010],n,x;
int main(){
  x=0;
  scanf("%d",&money);
  n=1000-money;
  for(int i=0;500<=n;i++){x++;n=n-500;}
  for(int i=0;100<=n;i++){x++;n=n-100;}
  for(int i=0;50<=n;i++){x++;n=n-50;}
  for(int i=0;10<=n;i++){x++;n=n-10;}
  for(int i=0;5<=n;i++){x++;n=n-5;}
  for(int i=0;1<=n;i++){x++;n=n-1;}
  printf("%d\n",x);
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

int main() {
    int coins[] = {500, 100, 50, 10, 5, 1};
    int price;
    while(true) {
        cin >> price;
        if (price == 0) break;

        int change = 1000 - price;
        int cnt = 0;
        for (int c : coins) {
            int v = change / c;
            cnt += v;
            change -= v * c;
        }

        cout << cnt << "\n";
    }

    return 0;
}

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

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

int main() {

	int change, coin;
	cin >> change;
	change = 1000 - change;

	coin = 0;
	for (int i = 0; i < 6; ++i) {
		if (change >= coins[i]) {
			coin += change / coins[i];
			change %= coins[i];
			if (!change)
				break;
		}
	}
	cout << coin << endl;

	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	int money = 0;

	int change = 0;



	while (1)
	{


		int count500 = 0;

		int count100 = 0;

		int count50 = 0;

		int count10 = 0;

		int count5 = 0;

		int count1 = 0;


		cin >> money;

		if (money == 0)break;


		change = 1000 - money;

		count500 = change / 500;

		count100 = (change - (count500 * 500)) / 100;

		count50 = (change - (count500 * 500) - (count100 * 100)) / 50;

		count10 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50)) / 10;

		count5 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10)) / 5;

		count1 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10) - (count5 * 5)) / 1;

		cout << count500 + count100 + count50 + count10 + count5 + count1 << endl;
	}

	return 0;
}

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

int main()
{

	int price, change, coin_num, cnt;
	int coin_kind[] = {500, 100, 50, 10, 5, 1};

	while(cin >> price, price > 0) {
		coin_num = 0;
		cnt = 0;
		change = 1000 - price;
		while(change > 0) {
			if(change - coin_kind[cnt] >= 0) {
				coin_num++;
				change -= coin_kind[cnt];
			}
			else {
				cnt++;
			}
		}
		cout << coin_num << endl;
	}

	return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
int n;while(true){cin>>n;if(n==0){break;}
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<endl;}}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m,a,b,c,d,e,f;
	cin>>n;
	m=1000-n;
	for(a=0;a<2;a++){
	    for(b=0;b<5;b++){
			for(c=0;c<2;c++){
				for(d=0;d<5;d++){
					for(e=0;e<2;e++){
						for(f=0;f<5;f++){
							if(a*500+b*100+c*50+d*10+e*5+f*1==m){
								cout<<a+b+c+d+e+f<<endl;
								break;
                            }
							}
						}
					}
				}
			}
	    }
	return 0;
	}

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
}