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 m1;
  while(1)
  {
   cin>>m1; 
   if(m1<=0||m1>=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;

   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
   }
 }
   
  return 0;
}

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

int main(void)
{
    int ans;
    int change;
    int money;
    
    while (1){
        scanf("%d", &money);
        if (money == 0) break;
        
        ans = 0;
        change = 1000 - money;
        while (change != 0){
            if (500 <= change){
                change -= 500;
                ans++;
                continue;
            }
            if (100 <= change){
                change -= 100;
                ans++;
                continue;
            }
            if (50 <= change){
                change -= 50;
                ans++;
                continue;
            }
            if (10 <= change){
                change -= 10;
                ans++;
                continue;
            }
            if (5 <= change){
                change -= 5;
                ans++;
                continue;
            }
            if (1 <= change){
                change -= 1;
                ans++;
                continue;
            }
        }
        printf("%d\n", ans);
    }
    
    return (0);
}

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

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

int main(){
	for(;;){
		int N;
		cin >> N;
		if(N == 0) break;
		N = 1000 - N;
		int res = 0;
		for(int i = 0; i < 6; i++){
			int num = N / c[i];
			res += num;
			N -= c[i] * num;
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int b;
	if (a >= 500)
	{
		a = a - 500;
		b++;
	}
	else if (a >= 100)
	{
		a = a - 100;
		b++;
	}
	else if (a >= 50)
	{
		a = a - 50;
		b++;
	}
	else if (a >= 10)
	{
		a = a - 10;
		b++;
	}
	else if (a >= 5)
	{
		a = a - 5;
		b++;
	}
	else if (a >= 1)
	{
		a = a - 1;
		b++;
	}
	else
	{
		cout << b << endl;
	}
	return 0;
}

C++: 

#include <iostream>
using namespace std;
int main(){
	while(true){

	int n,m;
	cin >> n;
	if(n == 0) return 0;
	m = 0;
	n = 1000-n;

	if(n>=500){
		m = n/500;
		n = n%500;
	}
	if(n>=100){
		m = m+n/100;
		n = n%100;
	}
	if(n>=50){
		m = m+n/50;
		n = n%50;
	}
	if(n>=10){
		m = m+n/10;
		n = n%10;
	}
	if(n>=5){
		m = m+n/5;
		n = n%5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

	}

}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=998244353,MAX=200001,INF=1<<30;

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

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

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

C++: #include <iostream>

using namespace std;

void solve()
{
	int p;
	while(cin >> p, p)
	{
		p = 1000 - p;
		int ans = 0;
		if(p >= 500)
		{
			p -= 500;
			++ans;
		}
		if(p >= 100)
		{
			int k = p / 100;
			p -= k * 100;
			ans += k;
		}
		if(p >= 50)
		{
			p -= 50;
			++ans;
		}
		if(p >= 10)
		{
			int k = p / 10;
			p -= k * 10;
			ans += k;
		}
		if(p >= 5)
		{
			p -= 5;
			++ans;
		}
		if(p >= 1)
		{
			ans += p;
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

C++: #include <iostream>

using namespace std;

int coin;

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