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 i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 5; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
}

C++: #include <iostream>

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

C++: #include <stdio.h>

const int money[] = { 500, 100, 50, 10, 5, 1 };
const int size = sizeof( money ) / sizeof( int );

int main ( void )
{
	int x, i, answer = 0;

	while ( 1 ) {
		scanf( "%d", &x );
		if ( x == 0 ) {
			break;
		}

		for ( i = 0; i < size; ++i ) {
			answer += x / money[i];
			x %= money[i];
		}

		printf( "%d\n", answer );
	}

	return 0;
}

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

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

C++: #include <iostream>

using namespace std;

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		n = 1000 - n;
		int answer = 0;
		for(int i = 0; n > 0; i++){
			while(n >= COINS[i]){
				n -= COINS[i];
				answer++;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)

int main()
{
  int p[] = {500,100,50,10,5,1};
  int data;
  while(cin >> data,data){
    data = 1000 - data;
    int cnt = 0;
    Rep(i,6) {
      while(p[i] <= data) {
	data -= p[i];cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


int main(void){

	while( true ) {
		int n;
		cin >> n;
		if( !n ) break;
		n = 1000 - n;
		int ans = 0;
		int p[] = { 500, 100, 50, 10, 5, 1 };
	
		for( int i = 0; i < 6; i++ ) {
			ans += n / p[i];
			n %= p[i];
		}
		cout << ans << endl;
	}

    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;


int main(){

	int coin[6] ={ 500,100,50,10,5,1 },sum,price;

	while(true){
		scanf("%d",&price);
		if(price == 0)break;

		sum = 0;

		price = 1000 - price;

		for(int i = 0; i <= 5; i++){
			while(price >= coin[i]){
				price -= coin[i];
				sum++;
			}
		}

		printf("%d\n",sum);
	}

    return 0;
}

C++: #include <iostream>

int ans;
int count(int change)
{
	if(!change)
		return 0;
	if(change >= 500){
		ans += change / 500;
		count(change % 500);
	}
	else if(change >= 100){
		ans += change / 100;
		count(change % 100);
	}
	else if(change >= 50){
		ans += change / 50;
		count(change % 50);
	}
	else if(change >= 10){
		ans += change / 10;
		count(change % 10);
	}
	else if(change >= 5){
		ans += change / 5;
		count(change % 5);
	}
	else if(change >= 1){
		ans += change / 1;
		count(change % 1);
	}
}

int main()
{
	int pay;
	while(1){
		ans=0;
		std::cin >> pay;
		if(!pay)
			break;

		int change = 1000 - pay;

		count(change);

		std::cout << ans << std::endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!

  while(true){
   int t;
 cin>>t;
   if(t==0){
   break;
   }
  

 int s=1000-t;
 int w=s/500;
 int e=(s%500)/100;
  int r=((s%500)%100)/50;
  int y=(((s%500)%100)%50)/10;
  int u=((((s%500)%100)%50)%10)/5;
  int o=(((((s%500)%100)%50)%10)%5);
  cout<< w+e+r+y+u+o <<endl;
}
 
}

C++: #include <iostream>

using namespace std;

int main() {
	int a;
	cin >> a;
	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>
using namespace std;
int main() {
	int ki, co=0;
	while (1) {
		co = 0;
		cin >> ki;
		if (ki == 0) { break; }
		ki = 1000 - ki;
		if (ki >= 500) {
			ki = ki - 500;
			co++;
		}
		if (ki >= 100) {
			while(2){
				ki = ki - 100;
				co++;
				if (ki < 100) { break; }
			}
		}
		if (ki >= 50) {
			ki = ki - 50;
			co++;
		}
		if (ki >= 10) {
			while(2){
				ki = ki - 10;
				co++;
				if (ki < 10) { break; }
			}
		}
		if (ki >= 5) {
			ki = ki - 5;
			co++;
		}
		if (ki >= 1) {
			while(2){
				ki = ki - 1;
				co++;
				if (ki == 0) { break; }
			}
		}
		cout << co << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <list>
#include <vector>
#include <deque>
#include <numeric>

using namespace std;
int main() {
	int n;
	int fh, h, fty, ten, f, i;
	int th = 1000;
	for (;;) {
		cin >> n;
		if (n == 0)break;
		th -= n;
		fh = th / 500;
		th -= 500 * fh;
		h = th / 100;
		th -= 100 * h;
		fty = th / 50;
		th -= 50 * fty;
		ten = th / 10;
		th -= 10 * ten;
		f = th / 5;
		th -= 5 * f;
		i = th;
		cout << fh + h + fty + ten + f + i << endl;
		th = 1000;
	}
	


}

C++: // quest1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	int money, reverse, count = 0;

	scanf("%d", &money);
	reverse = 1000 - money;

	while (reverse >= 500) {
		reverse -= 500;
		count++;
	}
	while (reverse >= 100) {
		reverse -= 100;
		count++;
	}
	while (reverse >= 50) {
		reverse -= 50;
		count++;
	}
	while (reverse >= 10) {
		reverse -= 10;
		count++;
	}
	while (reverse >= 5) {
		reverse -= 5;
		count++;
	}
	while (reverse >= 1) {
		reverse -= 1;
		count++;
	}

	printf("%d", count);

    return 0;
}

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

int main(){
	int x, y = 0;
	scanf("%d", &x);
	x = 1000 - x;
	while (x >= 500){
		x -= 500;
		y++;
	}
	while (x >= 100){
		x -= 100;
		y++;
	}
	while (x >= 50){
		x -= 50;
		y++;
	}
	while (x >= 10){
		x -= 10;
		y++;
	}
	while (x >= 5){
		x -= 5;
		y++;
	}
	while (x >= 1){
		x -= 1;
		y++;
	}
	printf("%d\n", y);
	return 0;
}