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>
using namespace std;

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value%500; value/=500;
coins += value%100; value/=100;
coins += value%50; value/=50;
coins += value%10; value/=10;
coins += value%5; value/=5;
coins += value;
cout << coins;
}
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 <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/500a+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);}
}

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

int main(){
  int mon;
  while(cin >> mon,mon){
    int sum = 0;
    mon = 1000 - mon;
    sum += mon / 500;
    mon %= 500;
    
    sum += mon / 100;
    mon %= 100;
    
    sum += mon / 50;
    mon %= 50;
    
    sum += mon / 10;
    mon %= 10;
    
    sum += mon / 5;
    mon %= 5;
    
    cout << sum + mon << endl;
  }
}

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

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num = 0;

		if (cost_return < 5) {
			num = cost_return;
			break;
		}
		else {
			if (cost_return < 10) {
				num = 1 + cost_return - 5;
			}
		}


		if (cost_return >= 500) {
			++num;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num;
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
	
	}
	

	for (int i = 0; i < j;++i) {
		CO num E
	}
}

C++: #include<iostream>

using namespace std;

int main(void) {
	int now, count;

	while(true) {
		cin >> now;
		if(now == 0) { break; }
		count = 0;
		now = 1000 - now;
		while(now > 0) {
			if(now >= 500) {
				now -= 500;
				count++;
			} else if(now >= 100) {
				now -= 100;
				count++;
			} else if(now >= 50) {
				now -= 50;
				count++;
			} else if(now >= 10) {
				now -= 10;
				count++;
			} else if(now >= 5) {
				now -= 5;
				count++;
			} else {
				now -= 1;
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int ans, n, rest, itr;
    const int coin[] = {500, 100, 50, 10, 5, 1};
    while(true){
        cin >> n;
        if(n == 0){
            break;
        }
        else {
            itr = 0;
            ans = 0;
            rest = 1000 - n;
            while(rest > 0){
                if(itr >= 6){
                    break;
                }
                else if(rest - coin[itr] >= 0){
                    ans++;
                    rest -= coin[itr];
                }
                else {
                    itr++;
                }
            }
            cout << ans << endl;
        }
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 3000
using namespace std;

int C[6]={1,5,10,50,100,500};
int T[MAX+1];
void douteki();

int main(){
  int n;
 

  while(cin >> n){
    douteki();
    cout << T[1000-n] << endl;
  }



}

void douteki(){
  for(int j=0;j<=MAX;j++)T[j]=10000;
  T[0]=0;
  for(int i=0;i<6;i++){
    for(int j=C[i];j<=MAX;j++){
      T[j]=min(T[j],T[j-C[i]]+1);
    }
  }

}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

int main()
{
  while(cin >>N,N){
  N =1000-N;
  int ans = 0;
  int c[6] ={500,100,50,10,5,1};
  for(int i =0;i < 6;i++){
   while(N/c[i]){
      ans++;
      N -=c[i];
    }
  }
  cout <<ans<<endl;
  }
  return 0;
}

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

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

	int money = 1000;
	int pay, change, i;

	cin >> pay;
	change = money - pay;

	while(1){
	if(change == 0) break;
	while(1){
		if(change - 500 >= 0){
			i += 1;
			change -= 500;
			break;
		}
		else if(change - 100 >= 0){
			i += 1;
			change -= 100;
			break;
		}
		else if(change - 50 >= 0){
                        i += 1;
                        change -= 50;
                        break;
                }
		else if(change - 10 >= 0){
                        i += 1;
                        change -= 10;
                        break;
                }
		else if(change - 5 >= 0){
                        i += 1;
                        change -= 5;
                        break;
                }
		else{
			i += 1;
			change -= 1;
			break;
		}
	}
	}
	
	cout << i << "\n";		

	return 0;
}

C++: #include<iostream>
using namespace std;
 
int main(){
   
  int n;

  while(cin>>n, n){
    int 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;
    
    cout<<cnt+n<<endl;
  }
   
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	while (true)
	{		
		int a;
		int i = 0;
		cin >> a;
		if (a == 0)break;
		int b = 1000 - a;
		while (b >= 500)
		{
			b = b - 500;
			i = i + 1;
		}
		while (b >= 100)
		{
			b = b - 100;
			i = i + 1;
		}
		while (b >= 50)
		{
			b = b - 50;
			i = i + 1;
		}
		while (b >= 10)
		{
			b = b - 10;
			i = i + 1;
		}
		while (b >= 5)
		{
			b = b - 5;
			i = i + 1;
		}
		while (b >= 1)
		{
			b = b - 1;
			i = i + 1;
		}
		cout << i << endl;
	}
	return 0;
}