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 num, cnt;

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

C++: #include <iostream>

using namespace std;

int main() {

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

	while(cin >> n) {
		if(!n) {
			break;
		}
		int t=0;
		n=1000-n;
		int i=5;
		while(i!=-1) {
			if(n>=a[i]) {
				n-=a[i];
				t++;
			}
			else {
				i--;
			}
		}

		cout << t << endl;
	}

	return 0;

}

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

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

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

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


int main(){

	int a[6]={500,100,50,10,5,1};
	int b,s;
	while(true){

	cin >> b;
	if(b==0) break;

	int coins=0;
	s=1000-b;
	rep(i,6){

	coins+=s/a[i]; s%=a[i];

	}

	cout << coins << endl;

	}

	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==0){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

C++: #include <iostream>
//#include <fstream>
#include <vector>
#include <string>
//#include <cstdlib>
//#include <algorithm>
//#include <set>
//#include <conio.h>
using namespace std;
 
int main(){
	int n;
	while(cin >> n&& n!=0){
		int sum=0,pri=1000-n;
		while(pri>=500){
			pri -=500;
			++sum;
		}
		while(pri>=100){
			pri -=100;
			++sum;
		}
		while(pri>=50){
			pri -=50;
			++sum;
		}
		while(pri>=10){
			pri -=10;
			++sum;
		}
		while(pri>=5){
			pri -=5;
			++sum;
		}
		while(pri>=1){
			pri -=1;
			++sum;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  n=1000-n;
  int a[]={500,100,50,10,5,1};
  int ans=0;
  for(int i=0;i<6;i++){
    while(n>=a[i]) n-=a[i],ans++;
  }
  cout<<ans<<endl;
  return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		N = 1000 - N;
		int ans = 0;
		set<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N /= m;
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

C++: #include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, m, c, j;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		m = 1000-n;
		c = 0;
		
		for(int i = 100; m != 0; i /= 10){
			j = 5 * i;
			if(m >= j){
				m -= j;
				c++;
			}
		
			while(m >= i){
				m -= i;
				c++;
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

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

int main() {

  long long int n;
  cin >> n;
  n = 1000 - n;

  long long int ans = 0;
  if ( n >= 500 ) {
    ans++;
    n -= 500;
  }
  ans += n / 100;
  n %= 100;

  if ( n >= 50 ) {
    ans++;
    n -= 50;
  }
  ans += n / 10;
  n %= 10;

  if ( n >= 5 ) {
    ans++;
    n -= 5;
  }
  ans += n / 1;

  cout << ans << endl;

  return 0;

}

C++: #include <iostream>
using namespace std;
int main(){
  int a,i=0,b;
  cin>>a;
  b=1000-a;
    if(b>=500){
      i=b/500;
      b=b%500;
    }
    if(b>=100){
      i+=b/100;
      b=b%100;
    }
    if(b>=50){
      i+=b/50;
      b=b%50;
    }
    if(b>=10){
      i+=b/10;
      b=b%10;
    }
    if(b>=5){
      i+=b/5;
      b=b%5;
    }
    if(b>=1)
      i+=b/1;

   cout<<i<<endl;
return 0;
}

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

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

	int pay, change, i;
	
	cin >> pay;
	
	change = 1000 - pay;

	while(1){
	if(change == 0 || change == 1000) break;
	else if(change < 0 || 1000 < change) 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;
		}
	}
	}
	
	if(pay == 0 ) return 0;
        else if(pay < 0 || 1000 < pay) return 0;
	else cout << i << "\n";

	return 0;
}