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;
typedef long long ll;
// Welcome to my source code!

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

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int t[]={500,100,50,10,5,1};
	int n,cnt=0;
	while(cin>>n,n){
	cnt=0;
	n=1000-n;
	for(int i=0;i<6;i++){
	while(t[i]<=n)n-=t[i],cnt++;
	}
	cout<<cnt<<endl;
	}
	return 0;
}

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

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

C++: #include<stdio.h>
int main(void)
{
	int x,a,b,c,d,e,f,g,h,i,j;
	scanf("%d %d %d %d %d %d %d %d %d %d",&x,&a,&b,&c,&d,&e,&f,&g,&h,&i);
	j=x-(a+b+c+d+e+f+g+h+i);
	printf("%d\n",j);
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a;
	cin >> a;
	if (a == 0)
	{

	}
	else
	{
		int b = 0;
		a = 1000 - a;
		for (; a != 0;)
		{
			if (a >= 500)
			{
				a = a - 500;
				b++;
			}
			else if (a >= 100)
			{
				a = a - 100;
				b++;
			}
			else if (a >= 50)
			{
				a = a - 50;
				b++;
			}
			else if (a >= 10)
			{
				a = a - 10;
				b++;
			}
			else if (a >= 5)
			{
				a = a - 5;
				b++;
			}
			else if (a >= 1)
			{
				a = a - 1;
				b++;
			}
		}
		cout << b << endl;
	}
	return 0;
}

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

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

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	if (price != 0)
	{
		while (oturi > 0)
		{
			if (oturi >= 500)
			{
				count++;
				oturi -= 500;
			}
			else if (oturi >= 100)
			{
				count++;
				oturi -= 100;
			}
			else if (oturi >= 50)
			{
				count++;
				oturi -= 50;
			}
			else if (oturi >= 10)
			{
				count++;
				oturi -= 10;
			}
			else if (oturi >= 5)
			{
				count++;
				oturi -= 5;
			}
			else if (oturi >= 1)
			{
				count++;
				oturi -= 1;
			}
		}	
	}

	cout << count << endl;

	getchar;
	getchar;
	return 0;
}

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(coin!=0){
	cout<<coin<<endl;
	}
	return 0;

}

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

using namespace std;

int main() {

  const array<int, 6> coins = { 500, 100, 50, 10, 5, 1 };

  while(true) {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    n = 1000 - n;
    int count = 0;
    for ( auto coin : coins ) {
      if ( n >= coin ) {
    	count += (n / coin);
    	n %= coin;
      }
    }
    cout << count << 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;
		
		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>
using namespace std;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	while (1){
		cin >> a;
		if (a == 0){ break; }
		c = 0;
		a = 1000 - a;
		b = a;
		b = a / 500;
		c = c + b;
		a = a % 500;
		b = a / 100;
		c = c + b;
		a = a % 100;
		b = a / 50;
		c = c + b;
		a = a % 50;
		b = a / 10;
		c = c + b;
		a = a % 10;
		b = a / 5;
		c = c + b;
		a = a % 5;
		b = a;
		c = c + b;
		cout << c << endl;
		a = 0;
		b = 0;
		c = 0;
	}
	return 0;
}

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

int main()
{
	int a;
	
	while(true)
	{
		int h=0;
	cin>>a;
	a=1000-a;
	if(a==1000)return 0;
	while(a>=500)
	{
		a=a-500;
		h=h+1;
		
	}
	while(a>=100)
	{
	a=a-100;
	h=h+1;
	}
	while(a>=50)
	{
	a=a-50;
	h=h+1;
	}
	while(a>=10)
	{
	a=a-10;
	h=h+1;
	}
	while(a>=5)
	{
	a=a-5;
	h=h+1;
	}
	while(a>=1)
	{
	a=a-1;
	h=h+1;
	}
	cout<<h<<endl;
}

		return 0;

}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

    cin.tie(0);
    ios::sync_with_stdio(false);

    int value;
    reverse(coins, coins + 6);

    while (cin >> value, value)
    {
        value = 1000 - value;

        int ans = 0;

        REP(i, 6)
        {
            ans += value / coins[i];

            value %= coins[i];
        }

        cout << ans << endl;
    }

    return 0;
}