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 <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int coin[]={500,100,50,10,5,1};
int main()
{
	int n;
	while(scanf("%d",&n)&&n){
		int ans=0;
		n=1000-n;
		for(int i=0;i<6;i++){
			ans+=n/coin[i];
			n%=coin[i];
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

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

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

C++: #include <cstdio>
#include <iostream>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int many=0,ans=0,count=0;
	
	cin >> many ;
	ans=1000-many;
	count+=ans/500;ans=ans%500;
	count+=ans/100;ans=ans%100;
	count+=ans/50;ans=ans%50;
	count+=ans/10;ans=ans%10;
	count+=ans/5;ans=ans%5;
	count+=ans/1;ans=ans%1;
	
	printf("%d\n",count);
}

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

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

int main(){
	int cnt = 0,i = 5;
	cin >> X;
	X = 1000-X;
	while( X > 0 ){
		while( X >= change[i] ){
			X -= change[i];
			cnt++;
		}
		i--;
	}
	cout << cnt << endl;
	return 0;
}

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

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

int main(void){
    // Your code here!
    int tmp;
    while(cin>>tmp){
        if(tmp == 0){
            break;
        }
        int sum = 1000 - tmp;
        int cnt = 0;
        int s = 0;
        bool flag = false;
        while(true){
            if(sum == 0){
                flag = true;
                break;
            } else if(sum - coin[s] >= 0){
                sum -= coin[s];
                cnt += 1;
            } else{
                s++;
            }
            
        }
        
        cout << cnt << endl;

    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int co = 0;
		int a = 0;
		cin >> a;
		if (a == 0)
		{
			break;
		}

		int o = 0;
		o = 1000 - a;
        for (int i = 0; i < 100; i++)
        {
	        if (o == 0)
	        {
		        break;
	        }
	        if (o >= 500)
		    {
			    co++;
			    o -= 500;
		    }
		    else if (o >= 100)
		    {
			    co++;
			    o -= 100;
		    }
		    else if (o >= 50)
		    {
			    co++;
			    o -= 50;
		    }
		    else if (o >= 10)
		    {
			    co++;
			    o -= 10;
		    }
		    else if (o >= 5)
		    {
			    co++;
			    o -= 5;
		    }
		    else if (o >= 1)
		    {
			    co++;
			    o -= 1;
		    }
        }
		cout << co << endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>
#include<chrono>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define timenow std::chrono::system_clock::now()
#define timecal(start,end) std::chrono::duration_cast<std::chrono::milliseconds>((end)-(start)).count()

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))


constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  if(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  if(n >= 5){
    n -=5;
    ++ans;
  }
  cout << ans + n << endl;
  return 0;
}

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

const int data[6]={500,100,50,10,5,1};
int main() {
	// your code goes here
	int n;
	while(cin>>n && n){
		n=1000-n;
		int ans=0;
		for(int i=0;i<6;i++){
			ans+=n/data[i];
			n%=data[i];
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num;
	
	while (scanf("%d", &price), price){
		back = PAY - price;
		num = 0;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d\n", num);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
 
  while(true){
   int t;
 cin>>t;
   if(t==0){
   break;
   }
   
 
 int s=1000-t;
 int w=s/500;
 int e=(s%500)/100;
  int r=((s%500)%100)/50;
  int y=(((s%500)%100)%50)/10;
  int u=((((s%500)%100)%50)%10)/5;
  int o=(((((s%500)%100)%50)%10)%5);
  cout<< w+e+r+y+u+o <<endl;
}
  
}

C++: #include<iostream>


using namespace std;
int main(void){
    while(1){
    int a;
	int n;
	int c=0;
	cin>>a;
    if(a==0)break;
	int count=0;
	for(n=1000-a;n!=0;c++){
        if(n>=500)n-=500;
        else if(n>=100)n-=100;
        else if(n>=50)n-=50;
        else if(n>=10)n-=10;
        else if(n>=5)n-=5;
        else if(n>=1)n-=1;
    }
    cout << c << endl;

    }
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
    while(true){
        int num;
        cin >> num;
        if(num==0) break;
        num=1000-num;
        int sum=0;
        sum+=num/500;
        num%=500;
        sum+=num/100;
        num%=100;
        sum+=num/50;
        num%=50;
        sum+=num/10;
        num%=10;
        sum+=num/5;
        num%=5;
        sum+=num;
        cout << sum << "\n";
    }
    
    return 0;
}