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 >= 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<cstdio>
using namespace std;
int money[6]{500,100,50,10,5,1};
void solve(int price){
  int ans{0};
  for(int i{0} ; i< 6 ; i++){
    while(price >= money[i]){
      price -= money[i];
      ans++;
    }
  }
  printf("%d\n",ans);
}
int main(){
  int price;
  while(true){
    scanf("%d",&price);
    if(price == 0)
      break;
    solve(1000 - price);
  }
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt;
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 change[6]={1,10,50,100,500};
int cnt[6];
int n;

int main(){
cin >> n;
n = 1000-n;
for( int i = 5; i >= 0; i-- ){
while(n>=change[i]){
n-=change[i];
cnt[i]++;
}
}
int ans=0;
for(int i = 0; i < 6; i++ )
ans += cnt[i];
cout << ans << endl;
return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        
        if (a[i] == 0) break;
        
        int count = 0;
        int n = 1000-a[i];
        while (n % 500 == 0) {
            n -= 500;
            count++;
        }
        while (n % 100 == 0) {
            n -= 100;
            count++;
        }
        while (n % 50 == 0) {
            n -= 50;
            count++;
        }
        while (n % 10 == 0) {
            n -= 10;
            count++;
        }
        while (n % 5== 0) {
            n -= 5;
            count++;
        }
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

int main(){
	for(int i=0; i<5; i++){

		int C;
		
		cin >> C ;


		cout << (1000-C)/500 + (1000-C)/100-5*((1000-C)/500) + 
				(1000-C)/50-2*((1000-C)/100) + (1000-C)/10-5*((1000-C)/50) +
				(1000-C)/5-2*((1000-C)/10) + (1000-C)-5*((1000-C)/5) << endl;
	}



}

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

int main() {
	int n,a,i=0;
	cin>>n;
	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;
	return 0;
}

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

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

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		n=1000-n;
		int res=0;
		res+=n/500;
		n-=n/500*500;
		res+=n/100;
		n-=n/100*100;
		res+=n/50;
		n-=n/50*50;
		res+=n/10;
		n-=n/10*10;
		res+=n/5;
		n-=n/5*5;
		res+=n;
		cout<<res<<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_s("%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<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

int main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n",ans);
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int coin[10] = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5};

int main(){
	int n, ans;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		n = 1000 - n;
		ans = 0;
		for(int loop = 0; loop < 4; loop++){
			ans += coin[n % 10];
			n /= 10;
		}
		
		printf("%d\n", ans);
	}
	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<iostream>
using namespace std;
int main(){
int price,cnt=0;
int div[6]=[500,100,50,10,5,1];
int i;
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
for(i=0;i<6;i++){
if((price/div[i])!=0){
cnt+=(price/div[i]);
price-=(price/div[i])*div[i];
}
}
cout<<cnt<<endl;
cnt=0;
}
return 0;
}