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

#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  const int coin[] = {500, 100, 50, 10, 5, 1};
  int n;

  while (cin >> n, n){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <fstream>

using namespace std;

const int INF = 100000000;

int main(){

	int dp[1000];
	fill(dp,dp+1000,INF);
	dp[0] = 0;

	int serve[] = {1,5,10,50,100,500};
	for(int i = 1; i < 1000; i++){
		for(int j = 0; j < 6; j++){
			if(i - serve[j] >= 0){
				dp[i] = min(dp[i],dp[i-serve[j]] + 1);
			}
			else
				break;
		}
	}

	int n;
	while(cin >> n && n != 0){
		int left = 1000 - n;
		cout << dp[left] << endl;
	}

	return 0;
}

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

int main(){
int s=0;
int a[]={500,100,50,10,5,1};
int b;
while(scanf("%d",&b),b){
	int c=1000-b;
	for(int d=0;d<6;d++){
		int e=c/a[d];
		s+=e;
		c-=e*a[d];
	}
	printf("%d\n",s);
}
}

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);
	}
}

C++: #include <iostream>

using namespace std;

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<int> pay;
    int coins[] = {500,100,50,10,5,1};
    while(true){
          int temp;
          cin >> temp;
          if(temp == 0)break;
          pay.push_back(temp);
    }
    
    for(int i = 0;i < pay.size();i++){
          int change = 1000 - pay[i];
          int total = 0;
          for(int j = 0;j < 6;j++){
                int n = change / coins[j];
                change -= n * coins[j];
                total += n;
          }
          cout << total << endl;
    }
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a, b;
	while(cin >> a){
		b = 1000 - a;
		int ret = 0;
		while(b != 0){
			if(b >= 500){
				ret+= b/500;
				b %= 500;
			}else if(b >= 100){
				ret += b/100;
				b %= 100;
			}else if(b >= 50){
				ret += b/50;
				b %= 50;
			}else if(b >= 10){
				ret += b/10;
				b %= 10;
			}else if(b >= 5){
				ret += b/5;
				b %= 5;
			}else{
				ret += b;
				b = 0;
			}
		}
		cout << ret << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    cin >> money;

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    return 0;
}

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

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

C++: #include<iostream>
using namespace std;
int main(){
	int coin[6] = {500,100,50,10,5,1};
	int money, count=0;
	cin >> money;
	money=1000-money;
	for(int i=0; i<6; i++){
		while(money >= coin[i]){
			count++;
			money-=coin[i];
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include <cstdio>
using namespace std;
int main()
{
 while(1){
  int a;
  scanf("%d",&a);
 if(a==0) return 0;
  a=1000-a;
  printf("%d\n",a/500+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);
 }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

int coin[6]={500,100,50,10,5,1};
int main(){
  while (1) {
    int n;
    cin>>n;
    if(n==0) break;
    int cost=1000-n;
    int ans=0;
    for(int i=0; i<6; i++){
      int a=cost/coin[i];
      ans+=a;
      cost-=coin[i]*a;
    }
    
    cout<<ans<<en
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    int m,n;
    cin >> m;
    while(m!=0){
       n = 1000 - m;
       cout << n/500 + (n%500)/100 +(n%100)/50+ (n%50)/10 +(n%10)/5 + (n%5) << endl;
       cin >> m;
    }
}

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

int main(){
	while(1){
		int n, p=1000, ans=0, i=0;
		int m[6]={500, 100, 50, 10, 5, 1};
		
		scanf(" %d", &n);
		if(n==0) break;
	
		p-=n;
		for(int i=0; i<6; ++i){
			if(p>=m[i]){
				int t=p/m[i];
				ans+=t;
				p-=m[i]*t;
			}			
		}
	
		printf("%d\n", ans);
	}

	return 0;
}

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