Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

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;
			}
			/*else {
				if (cost_return < 100) {
					num += (cost_return / 10);
					if (cost_return % 10 < 5) {
						num += cost_return % 10
					}
					else {
						num += 1 + cost_return - 5;
					}
				}
				else
				{
					if (cost_return < 500) {
						num += (cost_return / 100);
						if (cost_return % 100 < 5) {
							num += cost_return % 10
						}
						else {
							num += 1 + cost_return - 5;
						}
					}
				}
			}*/
		}
		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		/*if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1){
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

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

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

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

int main() {
	int x;
	cin>>x;
	int sum=1000-x;
	int ans=0;
	if(sum!=0)ans+=sum/500;
	sum%=500;
	if(sum!=0)ans+=sum/100;
	sum%=100;
	if(sum!=0)ans+=sum/50;
	sum%=50;
	if(sum!=0)ans+=sum/10;
	sum%=10;
	if(sum!=0)ans+=sum/5;
	sum%=5;
	ans+=sum;
	cout<<ans<<endl;
	// your code goes here
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
	int a[6], sum[5] = {0};
    int i = 0;
    while(1){
        std::cin >> a[i];

        if (a[i] == 0) {
            break;
        }
		i++;
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

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

#include <stdlib.h>

using namespace std;

#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define SORT(x, n) sort(begin(x),begin(x)+n)

#define INF 2000000000000

int calc(int value){
	if(value - 500 >= 0){
		return value - 500;
	}
	else if(value - 100 >= 0){
		return value - 100;
	}
	else if(value - 50 >= 0){
		return value - 50;
	}
	else if(value - 10 >= 0){
		return value - 10;
	}
	else if(value - 5 >= 0){
		return value - 5;
	}
	else{
		return value - 1;
	}
}

int main()
{
	int price, oturi;
	while(true)
	{
		cin >> price;
		if(price == 0){ break; }
		oturi = 1000 - price;
		
		int count=0;
		while(true)
		{
			oturi = calc(oturi);
			//cout << oturi << endl;
			count++;
			if(oturi == 0){ break; }
		}
		
		cout << count << endl;
	}
	
	/*
	for(auto a : W){
		cout << a << endl;
	}
	*/
	
}

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

C++: #include<cstdio>
using namespace std;
int main(){
    int k[] = {500,100,50,10,5,1};
    int n;
    while(scanf("%d",&n),n){
    n = 1000-n;
    int ans = 1;
    for(int i = 0;;){
        if(n-k[i] == 0)break;
        if(n-k[i] > 0){
            ans++;
            n = n-k[i];
        }
        else{
            i++;
        }
    }
    printf("%d\n",ans);
    }
    return 0;
}

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

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 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))


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<bits/stdc++.h>
using namespace std;

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

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

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

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


int main() {
int n;
cin>>n;
n=1000-n;
int ans=0;
ans=ans+n/500;
n=n%500;

ans=ans+n/100;
n=n%100;

ans=ans+n/50;
n=n%50;

ans=ans+n/10;
n=n%10;

ans=ans+n/5;
n=n%5;
ans=ans+n;
cout<<ans;

	return 0;
}