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){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include<stdio.h>

int mian(void){
	int n,k;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		k += n /500;  n %=500;
		k += n/100;   n %=100;
		k += n/50;    n %= 50;
		k += n/10;    n %= 10;
		k += n/5;     k += n%5;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  
  cin >> money;
  oturi = 1000 - money;
  for(int i = 1000;oturi > 10;i /= 10){
    oturi %= i;
    if(oturi >= i/10){
      (oturi / (i/10) >= 5) ? (maisu += oturi / (i/10) - 4) : (maisu += oturi / (i/10));
    }
  }
  cout << maisu << endl;
    
    return 0;
  }

C++: #include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

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

C++: #include<iostream>

const int coins[] = {500, 100, 50, 10, 5, 1};
//int nums[] = {0, 0, 0, 0, 0, 0};

int run(){
	int x, x2, num = 0, t;
	int M = sizeof(coins) / sizeof(int);
	std::cin >> x;
	if( x == 0 ){ return 0; }
	x2 = 1000 - x;
	for( int i = 0; i < M; i++ ){
		t = x2 / coins[i];
		x2 -= t * coins[i];
		num += t;
	}
	std::cout << num << std::endl;
	return 1;
}

int main(){
	while( run() );
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d",sum);

	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int s,o,i;
	scanf("%d",&o);
	while(o !=0){
	s=1000-o;
	i=0;
	
		while(s>=500){
			s=s-500;
			i++;
		}
		while(s>=100){	
			s=s-100;
			i++;
		}
		while(s>=50){
			s=s-50;
			i++;
		}
		while(s>=10){
			s=s-10;
			i++;
		}
		while(s>=5){
			s=s-5;
			i++;
		}
		while(s>=1) {
			s=s-1;
			i++;
		}
	printf("%d\n",i);
	scanf("%d",&o);
	}			
	return 0;
}

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

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

int main(){

	//int c[6] = {500,100,50,10,5,1};
	int money, pay, change;

	scanf("%d", &pay);

	change = 0;
	money = 1000 - pay;

	for(int i = 0; i < 6; i++){

		change += money / c[i];
		money = money % c[i];
	}

	if(pay != 0) printf("%d\n", change);

	
	return 0;
}

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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int s, o;
	while(cin >> s, s) {
		s = 1000 - s;
		o = 0;
		while(s >= 500) {
			s -= 500;
			o++;
		}
		while(s >= 100){
			s -= 100;
			o++;
		}
		while(s >= 50){
			s -= 50;
			o++;
		}
		while(s >= 10){
			s -= 10;
			o++;
		}
		while(s >= 5){
			s -= 5;
			o++;
		}
		o += s;
		cout << o << endl;
	}

	return 0;

}

C++: #include<iostream>
using namespace std;
int t[]={500,100,50,10,5,1};
int main(){
  while(1){
    int n,ans=0;
    cin>>n;
    if(n==0)break;
    n=1000-n;
    for(int i=0;i<6;i++)ans+=n/t[i],n%=t[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(int argc, char const *argv[]){
    int n;
    const int m[6] = {500, 100, 50, 10, 5, 1};

    while (cin>>n, n){
        int ans = 0;
        int ret = 1000 - n;
        for (int i = 0; i < 6; i++){
            int t = ret / m[i];
            ret -= t * m[i];
            ans += t;
        }

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )

int dp[1001],tmp[]={500,100,50,10,5,1},n;
int main(){
  fill_n(dp,1001,INF);
  dp[0] = 0;
  for(int i = 0 ; i < 1001 ; i++ ){
    for(int j = 0 ; j < 6 ; j++ ){
      if(i-tmp[j]>=0) dp[i] = min(dp[i],dp[i-tmp[j]]+1);
    }
  }
  while(cin >> n , n) cout << dp[1000-n] << endl;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	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 <iostream>
using namespace std;
int main(){
  int a,i=0,b;
  while(1){
    i=0;
    cin>>a;
    if(a==0)break;
    b=1000-a;
      i=b/500;
      b=b%500;
      i+=b/100;
      b=b%100;
      i+=b/50;
      b=b%50;
      i+=b/10;
      b=b%10;
      i+=b/5;
      b=b%5;
      i+=b/1;
    cout<<i<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int ot(int m) {
	return m / 5 + m % 5;
}
int main() {
	int m;
	cin >> m;
	while (m != 0) {
		m = 1000 - m;
		int ans = 0;
		for (int i = 0; i < 4; i++) {
			int l = m % 10;
			ans += ot(l);
			m = m / 10;
		}
		cout << ans << endl;
		cin >> m;
	}
	return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

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

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  
  cin >> money;
  oturi = 1000 - money;
  for(int i = 1000;oturi > 10;i /= 10){
    oturi %= i;
    if(oturi >= i/10){
      (oturi / (i/10) >= 5) ? (maisu += oturi / (i/10) - 4) : (maisu += oturi / (i/10));
    }
  }
  cout << maisu << endl;
    
    return 0;
  }