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<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;
	*/

	//おつり
	while(true){
		int N;
		if(N == 0) break;
		
		int nedan;
		cin >> nedan;
		int oturi = 1000-nedan;
		int oo5 = 0,oo1 = 0,o5 = 0,o1 = 0,_5 = 0,_1 = 0;
		if(oturi >= 500)
		{
			oo5 = 1;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			oo1++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			o5 = 1;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			oo1++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			o5 = 1;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			oo1++;
			oturi -= 1;
		}

	}

	return 0;
}

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

int main() {
	int n;
	cin >> n;
	n = 1000 - n;
	int ans = 0, i;
	int w[5] = { 500,100,50,10,1 };
	for (i = 0; i <= 5; i++) {
		ans = ans + n / w[i];
		n = n - n / w[i]*w[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
int buy,oturi,kouka;
cin>>buy;
if(!buy==0){
buy=1000;
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 <bits/stdc++.h>

using namespace std;
int c[6] = {500,100,50,10,5,1};
int main(){

	int n;
	scanf("%d",&n);

	n = 1000 - n;
	int ans = 0;

	for(int i = 0;i < 6;i++){
		ans += (n / c[i]);

		n = n % c[i];
	}

	printf("%d\n",ans);

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

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

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

int main(){
int total;
int change;
int count=0;
while(true){
 cin>>total;
 if(total==0){
    break;
  } 
 change=1000-total;
 while(true){
   if(change>=500){
     change-=500;
     count++;
   }else if(change>=100){
     change-=100;
     count++;
   }else if(change>=50){
     change-=50;
     count++;
   }else if(change>=10){
     change-=10;
     count++;
   }else if(change>=5){
     change-=5;
     count++;
   }else{
     change--;
     count++;
    }
 }
 count<<count<<"\n";
 count=0;
}
return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	inin(x); x = abs(x - 1000);
	int ans = 0;
	ans += x / 500; x %= 500;
	ans += x / 100; x %= 100;
	ans += x / 50; x %= 50;
	ans += x / 10; x %= 10;
	ans += x / 5; x %= 5;
	ans += x;
	cout << ans << endl;
}

C++: #include<bits/stdc++.h>
using namespace std ;
int main()
{
    int moneySet[] = { 500 , 100 , 50 , 10 , 5 , 1 } ;
    int money = 0 ;
    int Count = 0 ;
    while(1)
    {
        cin >> money ;
        if ( money == 0 ) break ;
        money = 1000 - money ;

        for (int i = 0 ; i < 6 ; i++ )
        {
            while( money >= moneySet[i] )
            {
                Count++ ;
                money -= moneySet[i] ;
            }
        }

        cout << Count << endl ;
        Count = 0 ;
    }

    return 0 ;
}

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

C++: #include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <deque>
using namespace std;

int main()
{
	int money[100],pay[100],count[100] = {0},i = 0;

	while(1)
	{
		cin>>pay[i];
		if(pay[i] == 0)break;
		money[i] = 1000 - pay[i];

		while(money[i] >= 1)
		{
			if(money[i] >= 500)
			{
				money[i] -= 500;
				count[i]++;
			}
			else if(money[i] >= 100)
			{
				money[i] -= 100;
				count[i]++;
			}
			else if(money[i] >= 50)
			{
				money[i] -= 50;
				count[i]++;
			}
			else if(money[i] >= 10)
			{
				money[i] -= 10;
				count[i]++;
			}
			else if(money[i] >= 5)
			{
				money[i] -= 5;
				count[i]++;
			}
			else if(money[i] >= 1)
			{
				money[i] -= 1;
				count[i]++;
			}
		}
	i++;
	}
	for(int j=0; j<i; j++)
		cout<<count[j]<<endl;

	return 0;

}

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

int main() {
	int all, rem, count = 0, tmp;
	while (1) {
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
		return 0;
	}
	return 0;

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};
    int money = 1000;
    int count = 0;
    int i = 0;

    scanf("%d", &amount);

    money -= amount;

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

            count++;
        }
        else {
            i++;
        }
    }

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

    return (0);
}