Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

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

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

	if(n>=500){
		m = n/500;
		n = n%500;
	}
	if(n>=100){
		m = m+n/100;
		n = n%100;
	}
	if(n>=50){
		m = m+n/50;
		n = n%50;
	}
	if(n>=10){
		m = m+n/10;
		n = n%10;
	}
	if(n>=5){
		m = m+n/5;
		n = n%5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int m;
  while(cin>>m,m){
  int co=0;
  int o=1000-m;
  if(o>500){co++;o-=500;}
  while(o>=100){co++;o-=100;}
  while(o>=50){co++;o-=50;}
  while(o>=10){co++;o-=10;}
  while(o>=5){co++;o-=5;}
  while(o>=1){co++;o--;}

  cout<<co<<endl;
  }
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n, money, change;
  int coin[6] = {500, 100, 50, 10, 5, 1};

  while(1) {
    cin >> money;
    if(!money) break;

    change = 1000-money;

    int cnt = 0;
    REP(i, 6) {
      while(change/coin[i] > 0) {	
	cnt++;
	change -= coin[i];
      }
    }
    cout << cnt << endl;
  }
}

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

    
        cout <<y <<endl;
    }
    
}

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

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

int main(void){
	int mon, cnt;
	while(true){
		cin >> mon;
		if(mon == 0)	break;
		mon = 1000 - mon;
		cnt = 0;
		for(int i = 0; i < 6; i++){
			if(mon == 0)	break;
			cnt += mon / change[i];
			mon -= change[i] * (mon / change[i]);
		}
		cout << cnt << endl;
	}
  return 0;
}

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

int main() {
  int price,change,res=0;
  while(cin >> price) {
    if(price == 0) break;
    change = 1000 - price;
    for(int i=0;i<6;i++) {
      res += change/coin[i];
      change -= (change/coin[i]) * coin[i];
    }
    cout << res << endl;
    res = 0;
  }
}