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<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))


double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  if(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  if(n >= 5){
    n -=5;
    ++ans;
  }
  cout << ans + n << endl;
  return 0;
}

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

int main(){
  int n;
  const int coins[] = {500,100,50,10,5,1};
  while(cin >> n, n){
    n = 1000-n;
    int ans = 0;
    for(int i=0;i<6;i++){
      while(coins[i] <= n){
	n -= coins[i];
	ans++;
      }
    }
    cout << ans << endl;
  }
}

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

int kou[6]={500,100,50,10,5,1};
int main(){
	int N,res;
	while(true){
		cin>>N;
		if(N==0) break;
		N=1000-N;
		res=0;
		for(int i=0;i<6;i++){
			while(N>=kou[i]){
				res++;
				N-=kou[i];
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

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


int main() {
int n;
cin>>n;
n=1000-n;
int ans=0;
ans=ans+n/500;
n=n%500;

ans=ans+n/100;
n=n%100;

ans=ans+n/50;
n=n%50;

ans=ans+n/10;
n=n%10;

ans=ans+n/5;
n=n%5;
ans=ans+n;
cout<<ans;

	return 0;
}

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

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  while(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  while(n >= 5){
    n -=5;
    ++ans;
  }
  while(n >= 1){
    --n;
    ++ans;
  }
  cout << ans<< endl;
  return 0;
}

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

int money,c[1010],n,x;
int main(){
  while(true){
    x=0;
    scanf("%d",&money);
    if(money==0){break;}
    n=1000-money;
    for(int i=0;500<=n;i++){x++;n=n-500;}
    for(int i=0;100<=n;i++){x++;n=n-100;}
    for(int i=0;50<=n;i++){x++;n=n-50;}
    for(int i=0;10<=n;i++){x++;n=n-10;}
    for(int i=0;5<=n;i++){x++;n=n-5;}
    for(int i=0;1<=n;i++){x++;n=n-1;}
    printf("%d\n",x);
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int m;
  cin>>m;
  int co=0;
  int o=1000-m;
  if(o>500){co++;o-=500;}
  while(o>=100){co++;o-=100;}
  while(o>=50){co++;o-=50;}
  while(o>=10){co++;o-=10;}
  while(o>=5){co++;o-=5;}
  while(o>=1){co++;o--;}

  cout<<co<<endl;

}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[6], count=0, coin[] = { 500,100,50,10,5 };

    for (int i=0; i<6; i++) 
{
cin >> n[i];
if(!n[i])break;
}

    for (int i=0;i<6;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int change = 1000 - n;
        int count = 0;
        if (change >= 500) {
            change -= 500;
            count++;
        } 
        if (change >= 100) {
            int coin_100 = change / 100;
            change -= 100 * coin_100;
            count += coin_100;
        } 
        if (change >= 50) {
            change -= 50;
            count++;
        }
        if (change >= 10) {
            int coin_10 = change / 10;
            change -= 10 * coin_10;
            count += coin_10;
        }
        if (change >= 5) {
            change -= 5;
            count++;
        }
        count += change;
        cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a, b[] = { 500,100,50,10,5,1 }, ruio = 0;
	cin >> a;
	a = 1000 - a;
	for (int i = 0; i < 6; i++) {
		ruio += a/b[i];
		a = a%b[i];
	}
	cout << ruio << endl;
}

C++: #include <iostream>
#define REP(i, a, n) for(int a = 0; i < n; i++)
using namespace std;


int n, d, cnt;

int main(void) {
  while(cin >> n, n != 0) {
    d = 1000 - n;

    cnt = 0;
    while(d >= 500) d -= 500, cnt++;
    while(d >= 100) d -= 100, cnt++;
    while(d >=  50) d -=  50, cnt++;
    while(d >=  10) d -=  10, cnt++;
    while(d >=   5) d -=   5, cnt++;
    while(d >=   1) d -=   1, cnt++;

    cout << cnt << endl;
  }

  return 0;
}

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