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>
#include <cstdio>

using namespace std;

int main(){
	int price;
	int num[5] = {0};
	int i = 0;

	while (1){
		scanf("%d", &price);

		if (price != 0){
			price = 1000 - price;

			if (price / 500 != 0){
				num[i] += (price / 500);
				price -= (price / 500) * 500;	
			}
			if (price / 100 != 0){
				num[i] += (price / 100);
				price -= (price / 100) * 100;
			}
			if (price / 50 != 0){
				num[i] += (price / 50);
				price -= (price / 50) * 50;
			}
			if (price / 10 != 0){
				num[i] += (price / 10);
				price -= (price / 10) * 10;
			}
			if (price / 5 != 0){
				num[i] += (price / 5);
				price -= (price / 5) * 5;
			}
			if (price != 0){
				num[i] += price;
			}
			printf("%d", price);
		}
		else {
			break;
		}
		i++;
	}

	for (int i = 0; num[i] >= 1; i++){
		printf("%d\n", num[i]);
	}

}

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout<<b/500+c/100+d/50+e/10+f/5+g<<endl;
	return 0;
}

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

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

int main(){
	int n;
	while(cin >> n, n){
		ans = 0;
		n = 1000 - n;

		for(int i=0; i < 6; i++){
			ans += n / p[i];
			n -= n / p[i] * p[i];
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>

using namespace std;

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

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF       numeric_limits<int>::max()
#define NINF      numeric_limits<int>::min()
#define MOD       1000000007

using namespace std;
using Int = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<int> coin_vals{500, 100, 50, 10, 5, 1};

    while(true) {
        int in;
        std::cin >> in;
        if(in == 0) {
            break;
        }

        int ans    = 0;
        int change = 1000 - in;
        for(const auto& coin_val : coin_vals) {
            ans    += change / coin_val;
            change %= coin_val;
        }

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

    return 0;
}

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

using namespace std;

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

int main() {
	int a;
	while(true) {
		cin >> a;
		if(a==0) break;

		int oturi = 1000-a;

		int ans = 0;

		for(int i = 0; i < 6; i++) {
			int coin = changes[i];
			while(oturi-coin>=0) {
				oturi -= coin;
				ans++;
			}
		}

		cout << ans << endl;
	}
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
kouka=0;
}

return 0;
}

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	cin>>num1;
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int ans[11], an,n;
	an = 0;
	while (1) {
		cin >> n;
		if (n == 0) {
			goto a;
		}
		an = an + 1;
		ans[an] = 0;
		n = 1000 - n;
		while (n >= 500) {
			ans[an] = ans[an] + 1;
			n = n - 500;
		}
		while (n >= 100) {
			ans[an] = ans[an] + 1;
			n = n - 100;
		}
		while (n >= 50) {
			ans[an] = ans[an] + 1;
			n = n - 50;
		}
		while (n >= 10) {
			ans[an] = ans[an] + 1;
			n = n - 10;
		}
		while (n >= 5) {
			ans[an] = ans[an] + 1;
			n = n - 5;
		}
		while (n >= 1) {
			ans[an] = ans[an] + 1;
			n = n - 1;
		}
	}
a:;
	for (int i = 1; i <= an; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(){
  int coin[] = {500, 100, 50, 10, 5, 1};
  int n;
  while(std::cin >> n, n){
    int p = 0, ans = 0;
    n = 1000 - n;
    while(n != 0){
      while(n - coin[p] < 0)p++;
      n -= coin[p];
      ans++;
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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 < 6; 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;    
  }
  return -1;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  int c[] = {500,100,50,10,5,1};
  cin >> n;

  n = 1000-n;
  int ans =0;
  for( int i=0;i<6;i++ ){
    if( n >= c[i] ){
      ans += n / c[i];
      n = n% c[i];
    }
  }
  cout << ans << endl;
}

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


int main(){
    long long int n,ans=0;
    cin>>n;
    while(n!=0){
        n=1000-n;
        if(n/100>=5){
            ans+=n/100-4;
        }
        else{
            ans+=n/100;
        }
        if(n%10>=5){
            ans+=n%10-4;
        }
        else{
            ans+=n%10;
        }
        if((n/10)%10>=5){
            ans+=(n/10)%10-4;
        }
        else{
            ans+=(n/10)%10;
        }
        cout<<ans<<endl;
        ans=0;
        cin>>n;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy;
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
return 0;
}