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>

using namespace std;

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

int main()
{
    int inp;

    while (cin >> inp, inp) {
        int ans = 0;

        inp = 1000 - inp;
        for (int i = 0; i < 7; i++) {
            if (inp <= 0)
                break;
            else if (inp / m[i]) {
                ans += inp / m[i];
                inp = inp % m[i];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main(void){
  int coins[] = {500, 100, 50, 10, 5, 1};

  while(1){
  int ans = 0, n; cin >> n;
  if(n == 0) return 0;
  n = 1000 - n;
  for(int i=0; i < 6; i++){
    while(n >= coins[i]){
      ans++;
      n -= coins[i];
    }
  }
  cout << ans << endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	price=1000-price;
	while(1){
		if(flag==1){
			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;
		}
	}
	if(coins!=0){
	cout<<coin<<endl;
	}
	return 0;

}

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

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

C++: #include <iostream>

using namespace std;

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

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

        int r = 1000 - m;
        int sum = 0;
        for( auto const& c : cset ) {
            for(;;) {
                if ( r - c >= 0 ) {
                    ++sum;
                    r -= c;
                } else {
                    break;
                }
            }
        }
        cout << sum << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 ??????????????????JOI?????¨?????§?????????????????????
 JOI?????¨???????????¬??¨???500??????100??????50??????10??????5??????1?????????????????°???????????????
 ????????????????????°????°??????????????????????????????????????????????????????????
 ????????????JOI?????¨?????§????????????????????¬?????§1000?????????1??????????????????
 ???????????????????????????????????¬??¨????????°????±???????????????°????????????????????????
 =================================================================
 ?§£??¬=============================================================
 ????????????
 ================================================================
 */

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    int K[6] = {500,100,50,10,5,1};
    while(cin >> N,N){
        int res = 0;
        N = 1000 - N;
        for(int i = 0; i < 6;i++){
            res += N/K[i];
            N %= K[i];
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
 
using namespace std;
 
 
int main(){
 
    int coin[6] ={ 500,100,50,10,5,1 },sum,price;
 
    while(true){
        scanf("%d",&price);
        if(price == 0)break;
 
        sum = 0;
 
        price = 1000 - price;
 
        for(int i = 0; i <= 5; i++){
            while(price >= coin[i]){
                price -= coin[i];
                sum++;
            }
        }
 
        printf("%d\n",sum);
    }
 
    return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,count,maisu = 0,oturi[1000] = {};
  int money2[6] = {500,100,50,10,5,1};

  for(int i = 0;i >= 0;i++){
    cin >> money;
    count++;
    if(money == 0)
      break;
    oturi[i] = 1000 - money;
  }

  for(int j = 0;j < count;j++){ 
    for(int i = 0;i < 6;i++){
      maisu += oturi[j] / money2[i];
      oturi[j] %= money2[i];
    }
  }
  cout << maisu << endl;
    
    return 0;
  }

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

//????¬??????§?????£???????????°????±???????
int coin(int X){
    int ans = 0;
    //500
    ans = X / 500;

    //100
    ans = ans + (X % 500) / 100;

    //50
    ans = ans + ((X % 500) % 100) / 50;

    //10
    ans = ans + (((X % 500) % 100) % 50) / 10;

    //5
    ans = ans + ((((X % 500) % 100) % 50) % 10) / 5;

    //1
    ans = ans + (((((X % 500) % 100) % 50) % 10) % 5);

    return  ans;
}

int main(void){

    int i = 0;
    int ans[5];
    int input;
    while(1){
        cin >> input;
        if(input == 0){ break;}
        else{
            ans[i] = coin(1000-input);
        }
        i++;
    }

    for(int j = 0; j < i; j++){
        cout << ans[j] << endl;
    }

    return 0;
}