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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int C[6] = {500, 100, 50, 10, 5, 1};
int main(void){
	int n;
	while(cin >> n, n){
	cin >> n;
	n = 1000-n;
	int cnt = 0;
	int val = 0;
	while(n != 0){
		if(n - C[val] < 0){
			val++;
		}else{
			n -= C[val];
			cnt++;
		}
	}
	FIN(cnt);
}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  while(n!=0)
  {
    int now=1000;
    now-=n;
    int ans=0;
    while(now>=500)
    {
      now-=500;
      ans++;
    }
    while(now>=100)
    {
      now-=100;
      ans++;
    }
    while(now>=50)
    {
      now-=50;
      ans++;
    }
    while(now>=10)
    {
      now-=10;
      ans++;
    }
    while(now>=5)
    {
      now-=5;
      ans++;
    }
    while(now>=1)
    {
      now--;
      ans++;
    }
    cout<<ans<<endl;
    cin>>n;
  }
}

C++: #include<unordered_map>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<chrono>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n){
		n=1000-n;
		int sum=0;
		int c[6]={500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			while(n>=c[i]){
				n-=c[i];
				sum++;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>

using namespace std;

int main() {
	const int v[6] = {1, 5, 10, 50, 100, 500};
	int ans, c;

	while (1) {
		ans = 0;

		cin >> c;
		if (c == 0) break;

		c = 1000 - c;
		for (int i = 5; i >= 0; --i) {
			int tmp = c / v[i];
			c -= v[i] * tmp;
			ans += tmp;
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
				cnt++;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    n=1000-n;
    int ans=0;
    while(n>=500){
      ans++;
      n-=500;
    }
    while(n>=100){
      ans++;
      n-=100;
    }
    while(n>=50){
      ans++;
      n-=50;
    }
    while(n>=10){
      ans++;
      n-=10;
    }
    while(n>=5){
      ans++;
      n-=5;
    }
    while(n){
      ans++;
      n--;
    }
    cout<<ans<<endl;
  }
}

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

int main(){
    int coin[]={500,100,50,10,5,1};
    int n;
    int i;
    int result;
    cin >> n;
    while(n){
        n = 1000 - n;
        i = 0;
        result = 0;
        while(n){
            if(n - coin[i] >= 0){
                n -= coin[i];
                result++;
            }else{
                i++;
                if(i > 6){
                    break;
                }
            }
        }
        cout << result << endl;
        cin >> n;
    }
}

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

int main(){
while(true){
  int iwakurasisetudan;
  int b;
  int c;
  cin>>iwakurasisetudan;
if(iwakurasisetudan==0){break;
}else{  c=1000-a;
  b=c/500;
  c=c%500;
  b=b+c/100;
  c=c%100;
  b=b+c/50;
  c=c%50;
  b=b+c/10;
  c=c%10;
  b=b+c/5;
  c=c%5;
  b=b+c;
  cout<<b<<endl;
}}}

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

}

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

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	while(1)
	{
		cin>>k;
		if(k==0)
			break;
		k=1000-k;
		n=k/500+k%500/100+k%500%100/50+k%500%100%50/10+k%500%100%50%10/5+k%500%100%50%10%5;
		cout<<n<<endl;
	}
	return 0;
}

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	for(int i=0;i<150;i++){
	cin>>num1;
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	}
	return 0;
}

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

int main() {
  int price,change,res=0;
  cin >> price;
  change = 1000 - price;
  for(int i=0;i<6;i++) {
    res += change/coin[i];
    change -= (change/coin[i]) * coin[i];
  }
  cout << res << endl;
}

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	for(int i=0;i<1000;i++){
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
	}
}