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<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main(){
  int n, dp[1000], tmp[] = {500,100,50,10,5,1};
  fill_n(dp,1000,INF);
  dp[0] = 0;
  for(int i = 0 ; i < 1000 ; i++ ){
    for(int j = 0 ; j < 6 ; j++ ){
      if(i-tmp[j] >= 0) dp[i] = min( dp[i-tmp[j]] + 1, dp[i]);
    }
  }
  while(cin >> n , n ) cout << dp[1000-n] << endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, coin[6] = {500, 100, 50, 10, 5, 1};
	
	while (cin >> n, n) {
		int nn = 1000 - n, ans = 0;
		
		for_(i,0,6) {
			int d = nn / coin[i];
			ans += d;
			nn -= d * coin[i];
		}
		
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
	int a[6], sum[5] = {0};
    int i = 0;
    while(1){
        std::cin >> a[i];

        if (a[i] == 0) {
            break;
        }
		i++;
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

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

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

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

int main(){

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

	scanf("%d", &pay);

	//if(pay == 0) return 0;

	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 <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		while (b!=0)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			else if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			else if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			else if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			else if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			else if (b >= 1)
			{
				b = b - 1;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

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

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

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int x=0;
	int s[5]={500,100,50,10,1};
	cin>>n;
	
	n=1000-n;
	int k=0;
	while(n>0){
		if(n-s[k]>=0){
			n=n-s[k];
			x++;
		}
		else
			k++;
	}
	
	cout<<x<<endl;
	

}

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++: //============================================================================
// Name        : 0521.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {

	int x;
	int ans;

	while(1){

		cin >>x;
		x=(1000-x);

		ans=x/500;
		x=x%500;
		ans=ans+x/100;
		x=x%100;
		ans=ans+x/50;
		x=x%50;
		ans=ans+x/10;
		x=x%10;
		ans=ans+x/5;
		x=x%5;
		ans=ans+x/1;

		cout <<ans<<endl;
		if(x==0){
			break;
		}

	}

	return 0;
}

C++: #include<stdio.h>
int main()
{
  int y,ama,cou=0;
  while(1){
    cou=0;
    scanf("%d",&y);
    if(y==0){
      break;
    }
    ama=1000-y;
    if(ama>=500){
      cou+=ama/500;
      ama=ama%500;
    }
    if(ama>=100){
      cou+=ama/100;
      ama=ama%100;
    }
    if(ama>=50){
      cou+=ama/50;
      ama=ama%50;
    }
    if(ama>=10){
      cou+=ama/10;
      ama=ama%10;
    }
    if(ama>=5){
      cou+=ama/5;
      ama=ama%5;
    }
    if(ama>=1){
      cou+=ama/1;
      ama=ama%1;
    }
    printf("%d\n",cou);
  }
  return 0;
}