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)
	}
}

Python: a,b=1,0
while a>0:
    a=int(input())
    if a==0:
        break
    b=1000-a
    c=b//500
    d=b%500//100
    e=b%100//50
    f=b%50//10
    g=b%10//5
    h=b%5
    print(c+d+e+f+g+h)

Python: coin = [500,100,50,10,5,1]
while True:
 x = int(input())
 change = 1000-x
 if x == 0:break
 else:
     ans = 0
     for i in coin:
         ans += change // i
         change %= i
     print(ans)

Python: taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]

for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)

Python: while True:
    n = int(input())
    if n == 0:
        break
    oturi = 1000 - n
    li = [500,100,50,10,5,1]
    cnt = [0,0,0,0,0,0]
    for i in range(len(li)):
        cnt[i] = oturi//li[i]
        oturi -= cnt[i]*li[i]
    ans = 0
    for i in range(len(cnt)):
        ans += cnt[i]
    print(ans)

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		N = 1000 - N;
		int ans = 0;
		set<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N /= m;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>

int N;
int coin[6] = { 500,100,50,10,5,1 };
int ans = 0;

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

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ツ　<< endl;

  }

  return 0;

}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>

using namespace std;


int combart(int a) {
	int maisuu = 0;
	if (a >= 5) {
		maisuu++;
		a -= 5;
	}
	return maisuu + a;
}

int main(){

	int siharai;
	int oturi;

	while (1) {
		cin >> siharai;
		if (siharai == 0)break;

		oturi = 1000 - siharai;

		int hyaku = oturi / 100;
		int juu = (oturi % 100) / 10;
		int iti = oturi % 10;

		cout << combart(hyaku) + combart(juu) + combart(iti) << endl;
	}


//	system("pause");
    return 0;
}

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


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

	cout << m << endl;
    
    }
}

C++: main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
p=1000,s=0;
  p-=n;
  s+=p/500;
  p%=500;
  s+=p/100;
  p%=100;
  s+=p/50;
  p%=50;
  s+=p/10;
  p%=10;
  s+=p/5;
  p%=5;
  s+=p/1;
  p%=1;
  cout<<s<<endl;}

}

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n != 0){
	
		int a = 1000 - n;
		int cnt = 0;
		for(int i = 0; i < 6; ++i){
			while(a >= coin[i]){
				a -= coin[i];
				++cnt;
			}
		}
		
		cout << cnt << endl;
	}

	return 0;
}

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

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

int main() {

	int change, coins;

	while (cin >> change, change) {
		change = 1000 - change;

		coins = 0;
		for (int i = 0; i < 6; ++i) {
			if (change >= coin[i]) {
				coins += change / coin[i];
				change %= change / coin[i];
				if (!change)
					break;
			}
		}
		cout << coins << endl;
	}
	return 0;
}

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

int change[6]={1,5,10,50,100,500};
int cnt;
int n;

int main(){
	cin >> n;
	n = 1000-n;
	for( int i = 5; i >= 0; i-- ){
		while(n>=change[i]){
			n-=change[i];
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main() {int n,r,i;while(1){cin>>n;if(!n)break;n=1000-n,r=0;for(i=0;i<6;i++)r+=n/coin[i],n%=coin[i];cout<<res<<endl;}}

C++: #include <iostream>

using namespace std;

int main(){
  int money;
  while(cin >> money && money !=0){
    int count =0;
    int res = 1000 - money;
    for(int i=0;i<3;i++){
      //      cout << res << endl;
      count +=res %10;
      if(res % 10 >4){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}