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 <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <utility>
using namespace std;
int main() {
	int N;
	int C[]={500,100,50,10,5,1};
	while(scanf("%d",&N),N) {
		N=1000-N;
		int sum=0;
		for(int i=0;i<6;i++) {
			sum+=N/C[i];
			N%=C[i];
		}
		printf("%d\n",sum);
	}
}

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

int main(){
  int n;
  while(cin>>n,n!=0){
    n = 1000-n;
    const vector<int> list = {500,100,50,10,5,1};
    int ans = 0;
    for(int i=0;i<list.size();i++){
      ans += n / list[i];
      n = n % list[i];
    }
    cout<<ans<<endl;
  }
}

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

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

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "\n";
 
    
    }
    return 0;

}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(n!=0){b=1000-a;
c=0;
if(b>=500){b=b-500; c=c+1;}
if(b>=100){while(b<100){b=b-100; c=c+1;}}
if(b>=50){b=b-50; c=c+1;}
if(b>=10){while(b<10){b=b-10; c=c+1;}}
if(b>=5){b=b-5; c=c+1;}
c=b+c;
cout << c<<endl;
}
}
}

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

int main() {
	int n,a,i=0;
	cin>>n;
	a=1000-n;
	if(a>=500){
		i+=1;
		a-=500;
	}
	if(a>=100){
		int b=a/100;
		i+=b;
		a-=100*b;
	}
	if(a>=50){
		i+=1;
		a-=50;
	}
	if(a>=10){
		int b=a/10;
		i+=b;
		a-=10*b;
	}
	if(a>=5){
		i+=1;
		a-=5;
	}
	if(a>=1)
		i+=a;
	cout<<i<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

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

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n;
const int coin[] = {500, 100, 50, 10, 5, 1};

int main()
{
  cin >> n;
  n = 1000 - n;

  int res = 0;
  rep(k, 6){
    res += n / coin[k];
    n -= n / coin[k] * coin[k];
  }

  cout << res << endl;

  return 0;
}

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

ll N;

ll solve(ll N) {
  ll M=1000-N;
  ll ans=0;
  ll a=M/500;
  M-=a*500;
  ll b=M/100;
  M-=b*100;
  ll c=M/50;
  M-=c*50;
  ll d=M/10;
  M-=d*10;
  ll e=M/5;
  M-=e*5;
  return a+b+c+d+e+M;
}
  

int main() {
  while(cin>>N) {
    if (N) cout<<solve(N)<<endl;
    else break;
  }
  return 0;
}

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

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

C++: #include <cstdio>

using namespace std;

int main(){

  while(1){


  int ans = 0;

  int n;

  scanf("%d",&n);

  if(n == 0) break;

  n = 1000 - n;

  int k[7] = {500,100,50,10,5,1};

  for(int i = 0;i < 6;i++){
    if(n == 0) break;
    ans += n / k[i];
    n = n % k[i];
  }

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

  }

  return 0;

}

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

const int c[] = {500, 100, 50, 10, 5, 1};

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

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

    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
	int x;
	int i = 0;

	scanf("%d", &x);

	x = 1000 - x;

	while (x >= 500 ) {
		i++;
		x -= 500;
	}
	while (x >= 100 ) {
		i++;
		x -= 100;
	}
	while (x >= 50 ) {
		i++;
		x -= 50;
	}
	while (x >= 10 ) {
		i++;
		x -= 10;
	}
	while (x >= 5 ) {
		i++;
		x -= 5;
	}
	while (x >= 1 ) {
		i++;
		x -= 1;
	}

	printf("%d\n", i);
	return (0);
}

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

int main(){

  int sum;
  int cash;

  while(cin >> cash , cash){
    cash = 1000-cash;
    sum = 0;
    sum += cash/500; cash%=500;
    sum += cash/100; cash%=100;
    sum += cash/50; cash%=50;
    sum += cash/10; cash%=10;
    sum += cash/5; cash%=5;
    sum += cash/1;
    
    cout<< sum << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (oturi >= a[i]){
			div_t d;

			d = div(oturi, a[i]);
			oturi = oturi - a[i] * d.quot;
			count = count + d.quot;
		}
	}
	printf("%d\n",count);

	return 0;

	div(20, 3);

}