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 <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer[5] = { 0 };

	int in = 0, change = 0, n = 0;



	for (int j = 0; j < 5; j++) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
		answer[j] = n;
	}


	for (int j = 0; j < 5; j++) {
		if (answer[j] == 0) break;
		cout << answer[j] << endl;
	}

	return 0;
}

C++: #include <iostream>

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

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

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

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    const vector<int> coins = {500, 100, 50, 10, 5, 1};
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int ans = 0;
        for (auto c : coins) {
            int tmp = N / c;
            ans += tmp;
            N -= tmp * c;
        }
        cout << ans << endl;
    }
}

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

int main(){
	int x, y;
	while(scanf("%d", &x)){
		if(x == 0){
			break;
		}
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

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

C++: #include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

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

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	cin >> a;
	c = 0;
	a = 1000 - a;
	b = a;
	b = a / 500;
	c = c + b;
	a = a % 500;
	b = a / 100;
	c = c + b;
	a = a % 100;
	b = a / 50;
	c = c + b;
	a = a % 50;
	b = a / 10;
	c = c + b;
	a = a % 10;
	b = a / 5;
	c = c + b;
	a = a % 5;
	b = a;
	c = c + b;
	cout << c << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
//int coin[6] = {500,100,50,10,5,1};

int main(){
	int money, price;
	while(cin >> price){
		money = 1000-price;
		int count=0;
		while(money>=500) {count++; money-=500;}
		while(money>=100) {count++; money-=100;}
		while(money>=50) {count++; money-=50;}
		while(money>=10) {count++; money-=10;}
		while(money>=5) {count++; money-=5;}
		while(money>=1) {count++; money-=1;}
		cout << count << endl;
	}
	return 0;
}

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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;
    n = 1000 - n;

    long long int ans = 0;
    if ( n >= 500 ) {
      ans++;
      n -= 500;
    }
    ans += n / 100;
    n %= 100;

    if ( n >= 50 ) {
      ans++;
      n -= 50;
    }
    ans += n / 10;
    n %= 10;

    if ( n >= 5 ) {
      ans++;
      n -= 5;
    }
    ans += n / 1;

    cout << ans << 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 <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

int main() {
	int harai, oturi, koukakei ;/*?????£??????????????£????????¬??¨????¨?*/
	//int s500, s100, s50, s10, s5, s1 ;/*??¬??¨????????°*/
	div_t a500, a100, a50, a10, a5, a1 ;/*?????????*/
	scanf("%d", &harai);
	oturi = 1000 - harai ;
	a500 = div(oturi, 500);
	a100 = div(a500.rem, 100);
	a50 = div(a100.rem, 50);
	a10 = div(a50.rem, 10);
	a5 = div(a10.rem, 5);
	koukakei = a500.quot + a100.quot + a50.quot +a10.quot + a5.quot + a5.rem ;
	printf("%d", koukakei);
	return 0;
}

C++: #include <iostream>

using namespace std;

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

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	while( n <= 500 ){
		n = n-500;
		m++;
	}
	while( n <= 100 ){
		n = n-100;
		m++;
	}
	while( n <= 50 ){
		n = n-50;
		m++;
	}
	while( n <= 10 ){
		n = n-10;
		m++;
	}
	while( n <= 5 ){
		n = n-5;
		m++;
	}
	while( n <= 1){
		n = n-1;
		m++;
	}

	cout << m << endl;

	return 0;
}