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>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int c[] = {500, 100, 50, 10, 5, 1};
    while (true) {
        cin >> n;
        if (n == 0) break;
        n = 1000 - n;
        int ans = 0;
        rep(i, 0, 6) {
            ans += n/c[i];
            n -= n/c[i] * c[i];
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(1){
	cin>>a;
    if(a=0)break;
	b=(1000-a)/500;
	c=(1000-(a+500*b))/100;
	d=(1000-(a+500*b+100*c))/50;
	e=(1000-(a+500*b+100*c+50*d))/10;
	f=(1000-(a+500*b+100*c+50*d+10*e))/5;
	g=(1000-(a+500*b+100*c+50*d+10*e+5*f))/1;
        cout<<b+c+d+e+f+g<<endl;}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
int main() {
  while(true){
  int N;
  cin >> N;
  if(N == 0) break;
  int c = 1000 - N;
  int res = 0;
  if( c/500 >= 1) {
    res += c/500;
    c = c%500;
  }
  if( c/100 >= 1) {
    res += c/100;
    c = c%100;
  }
  if( c/50 >= 1) {
    res += c/50;
    c = c%50;
  }
  if( c/10 >= 1) {
    res += c/10;
    c = c%10;
  }
  if( c/5 >= 1) {
    res += c/5;
    c = c%5;
  }
  if( c >= 0) {
    res += c;
  }
  
  cout << res << 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;

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  while(cin >> t,t){
  int ans = 0;
  int t500 = (1000 - t)/500;
  int t100 = (1000 - t)/100 - 5*t500;
  int t10 = (1000 - t)/10 - t100*10 - t500*50; 
  ans = t500 + t100 + t10;
  if((1000 - t)%10 != 0)ans++;
  cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
	int a, b, c500, c100, c50, c10, c5, c1, sum = 0;
	cin >> a;

	while (1)
	{
		if (a == 0)
		{
			break;
		}

		b = 1000 - a;
		c500 = b / 500;
		b = b % 500;
		c100 = b / 100;
		b = b % 100;
		c50 = b / 50;
		b = b % 50;
		c10 = b / 10;
		b = b % 10;
		c5 = b / 5;
		b = b % 5;
		c1 = b / 1;

		sum = c500 + c100 + c50 + c10 + c5 + c1;
		cout << sum<<endl;
		cin >> a;
	}
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
}
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;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int coin[6] = {500,100,50,10,5,1};

int main(){
	int money, price;
	while(cin >> price){
		if(price==0) break;
		money = 1000-price;
		int count=0;
		for(int i=0; i<6; i++)
			while(money>=coin[i]) {count++; money-=coin[i];}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int gohyaku,hyaku,gozyu,zyu,go,ichi;
	int dai,otsuri,mai;
	scanf("%d",&dai);
	while(dai!=0){
		otsuri=1000-dai;
		gohyaku=0;
		hyaku=0;
		gozyu=0;
		zyu=0;
		go=0;
		ichi=0;
		while(otsuri!=0){
			while(otsuri>=500){
				otsuri=otsuri-500;
					gohyaku++;
			}
			while(otsuri>=100){
				otsuri=otsuri-100;
					hyaku++;
			}
			while(otsuri>=50){
				otsuri=otsuri-50;
					gozyu++;
			}
			while(otsuri>=10){
				otsuri=otsuri-10;
					zyu++;
			}
			while(otsuri>=5){
				otsuri=otsuri-5;
					go++;
			}
			while(otsuri>=1){
				otsuri=otsuri-1;
					ichi++;
			}
			mai=gohyaku+hyaku+gozyu+zyu+go+ichi;
			printf("%d\n",mai);
			scanf("%d",&dai);
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

int main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n", ans);
}

C++: #include <iostream>
using namespace std;
int count(int x, int c){
    if(x >= 500){
        return count(x-500, c+1);
    }
    if(x >= 100){
        return count(x-100, c+1);
    }
    if(x >= 50){
        return count(x-50, c+1);
    }
    if(x >= 10){
        return count(x-10, c+1);
    }
    if(x >= 5){
        return count(x-5, c+1);
    }
    if(x == 0){
        return c;
    }
    else {
        return count(x-1,c+1);
    }
}

int main (void){
    int x;
    while (true){
        cin >> x;
        if(x == 0) {
            break;
        }
        cout << count(1000 - x, 0) << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main()
{
    while (1)
    {
        ll a;
        cin >> a;
        if (a != 0)
        {
            ll tmp = 1000 - a;
            ll cnt = 0;
            cnt += tmp / 500;
            tmp = tmp % 500;
            cnt += tmp / 100;
            tmp = tmp % 100;
            cnt += tmp / 50;
            tmp = tmp % 50;
            cnt += tmp / 10;
            tmp = tmp % 10;
            cnt += tmp / 5;
            tmp = tmp % 5;
            cnt += tmp / 1;
            cout << cnt << endl;
        }
        else
        {
            return 0;
        }
    }
}