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++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>

using namespace std;

int main(int argc, char **argv){
	int n;
	int kane[] = { 500, 100, 50, 10, 5, 1 };
	int count;
	while (cin >> n && n != 0) {
		count = 0;
		n = 1000 - n;
		for (int i = 0; i < 6; i++) {
			count += (n / kane[i]);
			n %= kane[i];
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;
int n;
int coin[6] = {500, 100, 50, 10, 5, 1};

int main(int argc, char const* argv[])
{
	while(true){
			cin >> n;
			if(n == 0)break;
			n = 1000 - n;
			int res = 0;
			for(int i = 0; i < 6; i++){
					res += n / coin[i];
					n = n % coin[i];
			}
			cout << res << endl;
	}
	return 0;
}

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

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

int main(){
	int x, y = 0;
	scanf("%d", &x);
	x = 1000 - x;
	while (x >= 500){
		x -= 500;
		y++;
	}
	while (x >= 100){
		x -= 100;
		y++;
	}
	while (x >= 50){
		x -= 50;
		y++;
	}
	while (x >= 10){
		x -= 10;
		y++;
	}
	while (x >= 5){
		x -= 5;
		y++;
	}
	while (x >= 1){
		x -= 1;
		y++;
	}
	printf("%d\n", y);
	return 0;
}

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

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

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		 cout << onum << endl;
	}
   
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt;
cin>>price;
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=500;
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

int yen;
int ans=0;

while(cin>>yen){
if(yen==0) break;
ans=yen%5;
yen/=5;
ans+=yen%2;
yen/=2;
ans+=yen%5;
yen/=5;
ans+=yen%2;
yen/=2;
ans+=yen%5;
ans+=yen/5;
cout<<ans<<endl;
}
}

C++: #include<stdio.h>

int main(){
	int i=0,a,b[6]={500,100,50,10,5,1},c=0;
	scanf("%d",&a);
	a=1000-a;
	while(a!=0){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d",c);
}

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, 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>
using namespace std;
int main(){
int a,b,c=0;
while(1){
cin>>a;
  if(a==0){
       break;
}else{
    b=1000-a;
    c=b/500;
    c=c+b%500/100;
    c=c+b%500%100/50;
    c=c+b%500%100%50/10;
    c=c+b%500%100%50%10/5;
    c=c+b%500%100%50%10&5/1;
    a=0; 
   }
cout<< c <<endl;
} 
return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/10;
	i=z%10;
	c=b+y+m;
	printf("%d\n",c);
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, sum = 0;

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

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int c=1000-n,ans=0;
	while(c>=500) c-=500,++ans;
	while(c>=100) c-=100,++ans;
	while(c>=50) c-=50,++ans;
	while(c>=10) c-=10,++ans;
	while(c>=5) c-=5,++ans;
	while(c>=1) c-=1,++ans;
	cout<<ans<<endl;
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int N;
	scanf("%d",&N);
	int n = 1000 - N;
	int cnt = 0;
	if(500 <= n){
		n -= 500;
		cnt++;
	}
	if(100 <= n){
		cnt += n / 100;
		n %= 100;
	}
	if(50 <= n){
		cnt += n / 50;
		n %= 50;
	}
	if(10 <= n){
		cnt += n / 10;
		n %= 10;
	}
	if(5 <= n){
		cnt += n / 5;
		n %= 5;
	}
	cnt += n;
	printf("%d\n",cnt);
    return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<m<<endl;

}

}