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<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	scanf("%d", &a);
	while (1) {
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
			}
			if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int IN,answer;

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

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

int main() {
	int input;							//テ・ツ?・テ・ツ環崚ァツ板ィ
	int yen[] = {500,100,50,10,5,1};	//テァツ。ツャティツイツィテ」ツ?ョテァツィツョテゥツ。ツ?
	
	while(1) {
		cin >> input;	//テ・ツ?・テ・ツ環?
		if(input == 0) break;

		int ans = 0;
		input = 1000 - input;
		while(input > 0) {

			for(int i = 0; i < 6; i++) {
				if (input >= yen[i]) {
					input -= yen[i];
					ans++;
					break;
				} 
			}

		}

		cout << ans << endl;
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int i,j;
    int n;
    vector<int> v={500,100,50,10,5,1};
    while(1){
        cin>>n;
        if(n==0) break; 
        int cnt=0;
        n=1000-n;
        for(i=0;i<6;i++){
            while(n>=v[i]){
                n-=v[i];
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }

}

C++: #include<iostream>
using namespace std;
int main()
{
	int cost,change;
	int sum;
	int a,b,c,d,e,f;
	while(cin >>cost){
		if(cost==0) break;
		change=1000-cost;

		a=change%500%100%50%10%5;
		b=(change%500%100%50%10-a)/5;
		c=(change%500%100%50-a-5*b)/10;
		d=(change%500%100-a-5*b)/50;
		e=(change%500-a-5*b-10*c-50*d)/100;
		f=(change-a-5*b-10*c-50*d-100*e)/500;

		sum=a+b+c+d+e+f;
		cout <<sum<< endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>n;
	n=1000-n;
	int ans=0;
	REP(i,6) {
		if(n>=a[i]) {
			int tmp=n/a[i];
			ans+=tmp;
			n-=tmp*a[i];
		}
	}
	cout<<ans<<endl;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;

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

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 <bits/stdc++.h>
using namespace std;

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

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};
    int money = 1000;
    int count = 0;
    int i = 0;

    scanf("%d", &amount);

    money -= amount;

    while (i < 6){
        if (money - change[i] >= 0){
            money -= change[i];

            count++;
        }
        else {
            i++;
        }
        printf("money:%d\n", money);
        printf("i:%d\n", i);
    }

    printf("%d\n", count);

    return (0);
}

C++: #include<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 5) {
				a = a - 5;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
				cnt++;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}