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 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 <cstdio>

int main() {
	int num,n,i,a,b;
	i=0;
	scanf("%d",&num);
	n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=51){
		i++;
		n=(n-50);
	}
	if (n>=11){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=6){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	return 0;
}

C++: // 2012/12/14 Tazoe

#include <iostream>
using namespace std;

int main()
{
while(true){
	int n;
	cin >> n;

if(n==0)
break;

	int m = 1000-n;

	int sum = 0;

	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;

	sum += m;

	cout << sum << '\n';
}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
for(;;){
int n,ans=0;
cin >> n;
if(n==0)return 0;
n=1000-n;
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 << "\n";
}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef pair<int,int> P;
string s;
int k;
int INF=1000000000;
int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};

int main(){
    int r;
    int v[6]={500,100,50,10,5,1};
    while(true){
        cin>>r;
        if(r==0) break;
        int ans=0;
        int m=1000-r;
        int i=0;
        while(m!=0&&i<6){
            ans+=m/v[i];
            m%=v[i];
            i++;
        }
        cout<<ans<<endl;
    }
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	cin>>k;
	n=k/500+n%500/100+n%500%100/50+n%500%100%50/10+n%500%100%50%10/5+n%500%100%50%10%5;
	cout<<n<<endl;
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (oturi >= a[i]){
			div_t d;

			d = div(oturi, a[i]);
			oturi = oturi - a[i] * d.quot;
			count = count + d.quot;
		}
	}
	printf("%d\n",count);

	return 0;

	div(20, 3);

}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

int main(){
  while(scanf("%d",&n) && n){
    n = 1000 - n;
    printf("%d\n", n/500 + (n%500)/100 + (n%100)/50 + (n%50)/10 + (n%10)/5 + (n%5));
  }
  return 0;
}

C++: // 2011/11/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){

	int n;
	cin >> n;

	if(n==0)
		break;

	int m = 1000-n;

	int sum = 0;

	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;

	sum += m;

	cout << sum << endl;

	}

	return 0;
}

C++: #include <stdio.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);
	return 0;

}

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

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

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

int main() {
	int a,b=0;
	while(1){
		cin >> a;
		if(a==0) break;
		a=1000-a;
		if(a>=500){
			a-=500;
			b++;
		}

		while(1){
			if(a<100) break;
			a-=100;
			b++;
		}

		if(a>=50){
			a-=50;
			b++;
		}

		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}

		if(a>=5){
			a-=5;
			b++;
		}

		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout <<b << endl;
		b=0;
	}
	return 0;
}

C++: #include <cstdio>

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

int main(){
	while(scanf("%d", &n),n){
		ans = 0;
		n = 1000-n;
		for(int i = 0; i < 6; i++){ 
			ans += n/coin[i]; 
			n %= coin[i]; 
		}
		printf("%d\n", ans);
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

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

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

        int remain = 1000 - cost;
        const int n500 = remain / 500; remain -= 500 * n500;
        const int n100 = remain / 100; remain -= 100 * n100;
        const int n50  = remain / 50;  remain -= 50  * n50;
        const int n10  = remain / 10;  remain -= 10  * n10;
        const int n5   = remain / 5;   remain -= 5   * n5;
        const int n1   = remain;
        
        cout << n500 + n100 + n50 + n10 + n5 + n1 << endl;
    }
}

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

int main(){
int buy,oturi,kouka;
cin>>buy;
if(!buy==0){

oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
return 0;
}