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<bits/stdc++.h>
using namespace std;
int main(){
	int m;
	while(cin>>m,m){
    	int c[]={1,5,10,50,100,500};
    	m=1000-m;
    	int ans=0;
    	for(int i=5;i>=0;i--){
    		ans+=m/c[i];
    		m%=c[i];
    	}
    	cout<<ans<<endl;
	}
}

C++: #include <iostream>

int main(){
    while(true){
        int N;
        std::cin >> N;
        
        if(N == 0){
            break;
        }
        
        N = 1000 - N;
        
        int count = 0;
        
        count += N / 500;
        N %= 500;
        count += N / 100;
        N %= 100;
        count += N / 50;
        N %= 50;
        count += N / 10;
        N %= 10;
        count += N / 5;
        N %= 5;
        count += N / 1;
        N %= 1;
        
        std::cout << count << std::endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0;

    for (int i=0; i<5; i++) cin >> n[i];

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

	int s=1000 - n[i];

	int j = (s - s % 500)/500;
        count += j;
	s -= j*500;
        j = (s - s % 100)/100;
        count += j;
	s -= j*100;
        j = (s - s % 100)/100;
        count += j;
	s -= j*50;
        j = (s - s % 50)/50;
        count += j;
	s -= j*10;
        j = (s - s % 10)/10;
        count += j;
	s -= j*10;
        j = (s - s % 5)/5;
        count += j;
	s -= j*5;
        count += s;

	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	while(1){
		int tnok, yj;
		cin >> tnok;
		if (tnok == 0){
			return 0;
		}
		tnok = 1000 - tnok;
		if(tnok >= 500){
			yj = 1;
			tnok = tnok - 500;
		} else {
			yj = 0;
		}
		if(tnok >= 400){
			yj = yj + 4;
			tnok = tnok - 400;
		}
		else if(tnok >= 300){
			yj = yj + 3;
			tnok = tnok - 300;
		}
		else if(tnok >= 200){
			yj = yj + 2;
			tnok = tnok - 200;
		}
		else if(tnok >= 100){
			yj = yj + 1;
			tnok = tnok - 100;
		}
		if(tnok >= 50){
			yj = yj + 1;
			tnok = tnok - 50;
		}
		if(tnok >= 40){
			yj = yj + 4;
			tnok = tnok - 40;
		}
		else if(tnok >= 30){
			yj = yj + 3;
			tnok = tnok - 30;
		}
		else if(tnok >= 20){
			yj = yj + 2;
			tnok = tnok - 20;
		}
		else if(tnok >= 10){
			yj = yj + 1;
		tnok = tnok - 10;
		}
		if(tnok >= 5){
			yj = yj + 1;
			tnok = tnok - 5;
		}
		cout << tnok + yj <<endl;
	}
}

C++: g#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 <cstdio>

using namespace std;

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num = 0;
	while (cin >> pay)

	{
		if (!pay) break;

		pay = 1000 - pay;
		if (pay / 500 == 1){
			pay -= 500;
			num++;
		}
		for (;;){
			if (pay / 100 >= 1){
				pay -= 100;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 50 >= 1){
				pay -= 50;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 10 >= 1){
				pay -= 10;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 5){
				pay -= 5;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 1){
				pay -= 1;
				num++;
			}
			else break;
		}
		cout << num << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		if (b >= 500)
		{
			b = b - 500;
			c++;
		}
		else if (b >= 100)
		{
			b = b - 100;
			c++;
		}
		else if (b >= 50)
		{
			b = b - 50;
			c++;
		}
		else if (b >= 10)
		{
			b = b - 10;
			c++;
		}
		else if (b >= 5)
		{
			b = b - 5;
			c++;
		}
		else if (b >= 1)
		{
			b = b - 1;
			c++;
		}
		cout << c << endl;
	}	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
const int value[6] = {1, 5, 10, 50, 100, 500};
void pay(int n) {
    int rest = 1000 - n;
    int ans = 0;
    for (int i = 5; i >= 0; i--) {
        ans += (rest / value[i]);
        rest -= rest / value[i] * value[i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        pay(n);
    }
    return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

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

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

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int rest=1000-n;
		int fihu=rest/500;
		int hun=(rest-fihu*500)/100;
		int fif=(rest-fihu*500-hun*100)/50;
		int ten=(rest-fihu*500-hun*100-fif*50)/10;
		int five=(rest-fihu*500-hun*100-fif*50-ten*10)/5;
		int one=rest%5;
		cout<<fihu+hun+fif+ten+five+one<<endl;
	}
	return 0;
}

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