Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

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

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

int main(){
    int n;
    while(cin>>n,n){
            
        n=1000-n;
        int ans=0;
    
        for(int i=0;i<6;i++){
            ans+=n/coin[i];
            n%=coin[i];
        }
        
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

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

    while (scanf("%d", &amount), amount){
        int money = 1000;
        money -= amount;
        int count = 0;
        int i = 0;

        while (i < 6){
            if (money - change[i] >= 0){
                money -= change[i];
                count++;
            }
            else {
                i++;
            }
        }

        printf("%d\n", count);
    }

    return (0);
}

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[10];
	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[i] = 0;

		if (cost_return < 5) {
			num[i] = cost_return;
			continue;
		}
		else {
			if (cost_return < 10) {
				num[i] = 1 + cost_return - 5;
				continue;
			}
		}


		if (cost_return >= 500) {
			++num[i];
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num[i];
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num[i];
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num[i];
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num[i];
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num[i];
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		
	}
	
	for (int i = 0; i < j; ++i) {
		CO num[i] E
	}

	
}

C++: #include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
int main(){
	int n;
	int change[] = {500,100,50,10,5,1};
	while(scanf("%d",&n),n){
		n = 1000-n;
		int ans = 0;
		while(n > 0){
			ans++;
			for(int i = 0; i < 6; i++){
				if(n - change[i] >= 0){
					n -= change[i];
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    while( cin >> money ){

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    }
    return 0;
}

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

using namespace std;

vector<int> ans;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		int change = 1000 - n;
		int coin[] = {500,100,50,10,5,1};
		
		int tans = 0;
		for(int i = 0;i < 6;i++){
			int maisu = change / coin[i];
			if(maisu != 0){
				tans += maisu;
				change -= coin[i] * maisu;
			}
		}
		ans.push_back(tans);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin >> n; n = 1000 - n;
	int r = 0;
	r += n / 500; n %= 500;
	r += n / 100; n %= 100;
	r += n / 50; n %= 50;
	r += n / 10; n %= 10;
	r += n / 5; n %= 5;
	r += n;
	cout << r << endl;
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int a,i=0,b;
  while(1){
    i=0;
    cin>>a;
    if(a==0)break;
    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(){
int price,cnt=0,div[6]=[500,100,50,10,5,1];
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
for(i=0;i<6;i++){
if((price/div[i])!=0){
cnt+=(price/div[i]);
price-=(price/div[i])*div[i];
}
}
cout<<cnt<<endl;
cnt=0;
}
return 0;
}

C++: #include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int price;
	int num[5] = {0};
	int i = 0;

	while (1){
		scanf("%d", &price);

		if (price != 0){
			price = 1000 - price;

			if (price / 500 != 0){
				num[i] += (price / 500);
				price -= (price / 500) * 500;	
			}
			if (price / 100 != 0){
				num[i] += (price / 100);
				price -= (price / 100) * 100;
			}
			if (price / 50 != 0){
				num[i] += (price / 50);
				price -= (price / 50) * 50;
			}
			if (price / 10 != 0){
				num[i] += (price / 10);
				price -= (price / 10) * 10;
			}
			if (price / 5 != 0){
				num[i] += (price / 5);
				price -= (price / 5) * 5;
			}
			if (price != 0){
				num[i] += price;
			}
			printf("%d", price);
		}
		else {
			break;
		}
		i++;
	}

	for (int i = 0; num[i] >= 1; i++){
		printf("%d\n", num[i]);
	}

}

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

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

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

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

int main(){
	int n;
	while(cin >> n, n){
		ans = 0;
		n = 1000 - n;

		for(int i=0; i < 6; i++){
			ans += n / p[i];
			n -= n / p[i] * p[i];
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>

using namespace std;

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

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF       numeric_limits<int>::max()
#define NINF      numeric_limits<int>::min()
#define MOD       1000000007

using namespace std;
using Int = long long;

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

    vector<int> coin_vals{500, 100, 50, 10, 5, 1};

    while(true) {
        int in;
        std::cin >> in;
        if(in == 0) {
            break;
        }

        int ans    = 0;
        int change = 1000 - in;
        for(const auto& coin_val : coin_vals) {
            ans    += change / coin_val;
            change %= coin_val;
        }

        std::cout << ans << std::endl;
    }

    return 0;
}