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<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n;
	while (true) {
		cin >> n;
		if (n == 0) {
			cin >> n; return 0;
		}
		int sum = 1000 - n, num = 0;
		if (sum >= 500) {
			num++;
			sum = sum - 500;
		}
		if (sum >= 100) {
			num += sum / 100;
			sum = sum % 100;
		}
		if (sum >= 50) {
			num++;
			sum = sum - 50;
		}
		if (sum >= 10) {
			num += sum / 10;
			sum = sum % 10;
		}
		if (sum >= 5) {
			num++;
			sum = sum - 5;
		}
		num += sum;
		cout << num << endl;
	}
	cin >> n;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,c[6]={500,100,50,10,5,1},ans;
	while(true){
		cin>>n;
		if(!n)break;
		n=1000-n,ans=0;
		for(int i=0;i<6;i++)ans+=n/c[i],n%=c[i];
		cout<<ans<<endl;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		n = 1000 - n;
		int count = 0;
		count += n / 500;
		n %= 500;
		count += n / 100;
		n %= 100;
		count += n / 50;
		n %= 50;
		count += n / 10;
		n %= 10;
		count += n / 5;
		n %= 5;
		count += n;
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int i, ans;



int main() {


	while (true) {
		cin >> i;
		if (i == 0) break;
		i = 1000 - i;
		ans += i / 500;
		i %= 500;
		ans += i / 100;
		i %= 100;
		ans += i / 50;
		i %= 50;
		ans += i / 10;
		i %= 10;
		ans += i / 5;
		i %= 5;
		ans += i;
		cout << ans << endl;
		ans = 0;
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        n=1000-n;
        int count=0;
        if(n>=500){
            count++;
            n -= 500;
        //    cout<<"500"<<endl;
        }
        if(n>=100){
            while(n>=100){
                count++;
                n -= 100;
          //      cout<<"100"<<endl;
            }
        }
        if(n>=50){
            count++;
            n -= 50;
         //   cout<<"50"<<endl;
        }
        if(n>10){
            while(n>=10){
                count++;
                n -= 10;
             //   cout<<"10"<<endl;
            }
        }
        if(n>=5){
            count++;
            n -= 5;
          //  cout<<"5"<<endl;
        }
        count += n;
        cout<<count<<endl;
    }
}

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

int main() {
	int all, rem, count = 0, tmp;
	while (1) {
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
	}
	return 0;
}

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

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

int main(void){
	int mon, cnt = 0;
	cin >> mon;
	mon = 1000 - mon;
	for(int i = 0; i < 6; i++){
		if(mon == 0)	break;
		cnt += mon / change[i];
		mon -= change[i] * (mon / change[i]);
	}
	cout << cnt << endl;
  return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	for (; price > 0;)
	{
		if (price >= 500)
		{
			count++;
			price -= 500;
		}
		else if (price >= 100)
		{
			count++;
			price -= 100;
		}
		else if (price >= 50)
		{
			count++;
			price -= 50;
		}
		else if (price >= 10)
		{
			count++;
			price -= 10;
		}
		else if (price >= 5)
		{
			count++;
			price -= 5;
		}
		else if (price >= 1)
		{
			count++;
			price -= 1;
		}
	}

	cout << count << endl;

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
using namespace std;
 
 
int main(){
    int coin[6]={1,5,10,50,100,500},in,ans;
     
 
 while(1){
    ans=0;
    scanf("%d",&in);
     
    if(in==0)
      break;
 
    in=1000-in;
     
    for(int i=5;i>=0;i--){
        ans+=in/coin[i];
        in%=coin[i];
    }
     
    printf("%d\n",ans);
     
  }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	while(1)
	{
		cin>>k;
		if(k==0)
			break;
		n=k/500+k%500/100+k%500%100/50+k%500%100%50/10+k%500%100%50%10/5+k%500%100%50%10%5;
		cout<<n<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	
	while(cin >> n && n){
		int v = 1000 - n;
		int ret = 0;
		
		ret += v / 500;
		v -= (v / 500) * 500;
		
		ret += v / 100;
		v -= (v / 100) * 100;
		
		ret += v / 50;
		v -= (v / 50) * 50;
		
		ret += v / 10;
		v -= (v / 10) * 10;
		
		ret += v / 5;
		v -= (v / 5) * 5;
		
		ret += v;
		cout << ret << endl;
	}
}

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

C++: #include <cstdio>
using namespace std;
int main()
{
 int a;
 scanf("%d",&a);
 a=1000-a;
 printf("%d\n",((a/500))+((a/100)%5)+((a/50)%2)+((a/10)%5)+((a/5)%2)+(a%5));
}