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

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

    int x = 1000 - t;
    int cnt = 0;
    while (x > 0) {
      if (x / 500 > 0) {
        cnt += x / 500;
        x %= 500;
      } else if (x / 100 > 0) {
        cnt += x / 100;
        x %= 100;
      } else if (x / 50 > 0) {
        cnt += x / 50;
        x %= 50;
      } else if (x / 10 > 0) {
        cnt += x / 10;
        x %= 10;
      } else if (x / 5 > 0) {
        cnt += x / 5;
        x %= 5;
      } else if (x / 1 > 0) {
        cnt += x / 1;
        x %= 1;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "endl";
 
    
    }
    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 main(){
int price,cnt=0;
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
if((price/500)!=0){
cnt+=(price/500);
price-=(price/500)*500;
}
if((price/100)!=0){
cnt+=(price/100);
price-=(price/100)*100;
}
if((price/50)!=0){
cnt+=(price/50);
price-=(price/50)*50;
}
if((price/10)!=0){
cnt+=(price/10);
price-=(price/10)*10;
}
if((price/5)!=0){
cnt+=(price/5);
price-=(price/5)*5;
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
}
return 0;
}

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

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;



	while (true) {
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,o,s,m;
	
	scanf("%d",&m);
	
	a=0;
	b=0;
	c=0;
	d=0;
	e=0;
	f=0;
	s=0;
	
	o=1000-m;
	a=o/500;
	o=o-500*a;
	b=o/100;
	o=o-100*b;
	c=o/50;
	o=o-50*c;
	d=o/10;
	o=o-10*d;
	e=o/5;
	o=o-5*e;
	f=o/1;
	o=o-1*f;
	
	s=a+b+c+d+e+f;
	
	printf("%d\n",s);
	
	return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;
    }
   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
 }
   
  return 0;
}

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

C++: // 2011/09/09 Tazoe

#include <iostream>
using namespace std;

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

		n = 1000-n;

		int sum = 0;

		sum += n/500;
		n %= 500;

		sum += n/100;
		n %= 100;

		sum += n/50;
		n %= 50;

		sum += n/10;
		n %= 10;

		sum += n/5;
		n %= 5;

		sum += n;

		cout << sum << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int main() {
	int n;
	while (cin >> n && n != 0) {

		n = 1000 - n;
		int cnt = 0;
		int coin[] = { 500, 100, 50, 10, 5 };
		for (int i = 0; i < 5; ++i) {
			if (n >= coin[i]) {
				cnt += n / coin[i];
				n = n % coin[i];
			}
		}
		cnt += n;

		cout << cnt << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(!n) break;

        n = 1000-n;
        int cnt = 0;
        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;
    }
    return 0;
}

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

C++: #include<unordered_map>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<chrono>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n!=0){
		n=1000-n;
		int sum=0;
		int c[6]={500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			while(n>=c[i]){
				n-=c[i];
				sum++;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>

using namespace std;

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

	return 0;
}