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>
using namespace std;
int main() {
	while (true) {
		int a, b = 0;
		cin >> a;
		if (a == 0)
			break;
		a = 1000 - a;
		if (a >= 500) {
			a = a - 500;
			b = b + 1;
		}
		b = b + a / 100;
		a = a % 100;
		if (a >= 50) {
			a = a - 50;
			b = b + 1;
		}
		b = b + a / 10;
		a = a % 10;
		if (a >= 5) {
			a = a - 5;
			b = b + 1;
		}
		b = b + a;
		cout << b << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int input,oturi,output; 

int main(){
	while(1){
		oturi=0;
		output=0;
		cin>>input;
		if(input==0) break;
		oturi=1000-input;
		if(oturi>=500){
			output+=oturi/500;
			oturi-=oturi/500*500;
		}
		if(oturi>=100){
			output+=oturi/100;
			oturi-=oturi/100*100;
		}
		if(oturi>=50){
			output+=oturi/50;
			oturi-=oturi/50*50;
		}
		if(oturi>=10){
			output+=oturi/10;
			oturi-=oturi/10*10;
		}
		if(oturi>=5){
			output+=oturi/5;
			oturi-=oturi/5*5;
		}
		if(oturi>=1){
			output+=oturi/1;
			oturi-=oturi/1*1;
		}
		cout<<output<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu,money2[6] = {500,100,50,10,5,1};
  
  cin >> money;
  oturi = 1000 - money;

  for(int i = 0;i < 6;i++){
    maisu = oturi / money2[i];
    oturi %= money2[i];
  }
  cout << maisu << endl;
    
    return 0;
  }

C++: #include <iostream>

using namespace std;

int main(){
	int pay=0,coin=0;
	cin>>pay;
	pay=1000-pay;
	if(pay/500>=1){
		pay-=500;
		coin++;
	}
	if(pay>=100){
		coin+=pay/100;
		pay-=100*(pay/100);
	}
	if(pay>=50){
		coin+=pay/50;
		pay-=50*(pay/50);
	}
	if(pay>=10){
		coin+=pay/10;
		pay-=10*(pay/10);
	}
	if(pay>=5){
		coin+=pay/5;
		pay-=5*(pay/5);
	}
	if(pay>=1){
		coin+=pay;
	}
	cout<<coin<<endl;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
    while(1<2){
        int money,change,coin=0;

        cin>>money;
        if(money==0)break;
        change=1000-money;
        while(change-500>=0){
            coin+=1;
            change-=500;
            if(change<500)break;
        }
        
            while(change-100>=0){
            coin+=1;
            change-=100;
            if(change<100)break;
        }
        
                while(change-50>=0){
            coin+=1;
            change-=50;
            if(change<50)break;
        }
        
                while(change-10>=0){
            coin+=1;
            change-=10;
            if(change<10)break;
        }
        
                while(change-5>=0){
            coin+=1;
            change-=5;
            if(change<5)break;
        }
        
                while(change-1>=0){
            coin+=1;
            change-=1;
            if(change<1)break;
        }
        
        cout<<coin<<endl;
    }
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

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

C++: #include<iostream>
#using namespase 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;
)

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int pay, change, i;
	
	cin >> pay;
	
	change = 1000 - pay;

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

	
	return 0;
}

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

C++: // quest1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	int result[1000], suffix = 0;

	while (1) {
		int money, reverse, count = 0;

		scanf("%d", &money);
		if (money == 0) {
			break;
		}
		reverse = 1000 - money;

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

		result[suffix++] = count;
	}

	for (int i = 0; i < suffix; i++) {
		printf("%d\n", result[i]);
	}

    return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {

  int value,change;
  int coins;


  while(1) {

    cin >> value;

    if(value==0) break;

    coins=0;
    change=1000-value;

    coins+=change/500;
    change%=500;

    coins+=change/100;
    change%=100;

    coins+=change/50;
    change%=50;

    coins+=change/10;
    change%=10;

    coins+=change/5;
    change%=5;

    coins+=change/1;
    change%=1;

    cout << coins;

  }

  return 0;

}