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 <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, ans;
   while (cin >> n, n) {
      n = 1000 - n, ans = 0;
      for (int i = 0; i < 6; i++) {
         ans += n / t[i];
         n %= t[i];
      }
      cout << ans << endl;
   }
   return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int money=1000, price;
	int coin[6] = {500,100,50,10,5,1};
	int count,sum=0;
	cin >> price;
	money-=price;
	for(int i=0; i<6; i++){
		count=0;
		if(money >= coin[i]){
			count+=money/coin[i];
			money-=coin[i]*count;
		}
		sum+=count;
	}
	cout << sum << endl;
}

C++: #include <cstdio>
int coin[]={500,100,50,10,5,1};
int main() {
	int value;
	while(scanf("%d",&value),value) {
		value=1000-value;
		int ans=0;
		for(int i=0;i<6;i++) {
			ans+=value/coin[i];
			value%=coin[i];
		}
		printf("%d\n",ans);
	}
}

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

// #define MP make_pair
// #define PB push_back
// #define ALL(x)  (x).begin(),(x).end()
// #define RALL(x) (x).rbegin(),(x).rend()
// #define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
// #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
// #define rep(i, N)  for (int i = 0; i < (int)(N); i++)
// #define rrep(i, N) for (int i = N - 1; i >= 0; i--)
// #define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
// #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
// #define PB push_back

using namespace std;

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

// const int    INF  = 0x3f3f3f3f;
// const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
// const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int sum=0;
    int x;
    int cnt=0;
    while(1){
        cin>>x;
        if(!x)
            return 0;
        sum=1000-x;
        while(sum>0){
            if(sum>=500){
                cnt++;
                sum-=500;
            }
            else if(sum>=100){
                cnt++;
                sum-=100;
            }
            else if(sum>=50){
                cnt++;
                sum-=50;
            }
            else if(sum>=10){
                cnt++;
                sum-=10;
            }
            else if(sum>=5){
                cnt++;
                sum-=5;
            }
            else{
                cnt++;
                sum-=1;
            }
        }
        cout<<cnt<<endl;
        cnt=0;
    }


    return 0;
}

C++: #include<iostream>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/

	//おつり
	while(true){
		int N;
		if(N == 0) break;
		
		int nedan;
		cin >> nedan;
		int oturi = 1000-nedan;
		int onum= 0;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		cout << onum << endl;

	}

	return 0;
}

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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++)
#define downto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i >= _##i; i--)
#define downtil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

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

    loop {
        int N = 1000 - next<int>(), ans = 0;
        if(N == 1000) break;

        for(int coin : {500, 100, 50, 10, 5, 1}) {
            ans += N / coin;
            N %= coin;
        }

        cout << ans ln;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;

int main() {
  int n;
  while(cin >> n&&n!=0){
  int ans=0;
  n=1000-n;
  vector<int> c={500,100,50,10,5,1};
  r(i,6){
    int t=n/c[i];
    n-=t*c[i];
    ans+=t;
  }
  cout<<ans<<endl;
  }
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	int coin[10],price,sum;
	while(cin>>price,price){
		for(int i=0;i<10;i++){
			coin[i]=0;
		}
		sum=0;
		price=1000-price;
		if(price/500){
			coin[0]=(price/500);
			price=price-500*coin[0];
		}
		if(price/100){
			coin[1]=(price/100);
			price=price-100*coin[1];
		}
		if(price/50){
			coin[2]=(price/50);
			price=price-50*coin[2];
		}
		if(price/10){
			coin[3]=(price/10);
			price=price-10*coin[3];
		}
		if(price/5){
			coin[4]=(price/5);
			price=price-5*coin[4];
		}
		if(price/1){
			coin[5]=(price/1);
			price=price-coin[5];
		}
		for(int i=0;i<5;i++){
			sum=sum+coin[i];
		}
		cout<<sum<<endl;
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
int main()
{
	int t=0,yen,put=0,coin[6]={500,100,50,10,5,1};
	scanf("%d",&yen);
	yen=abs(1000-yen);
	for(int i=0;i<6;i++,t=0)
	{
		t=yen/coin[i];
		put+=t;
		yen-=t*coin[i];
	}
	printf("%d\n",put);
	//Sleep(1000);
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int ans=0;
		n=1000-n;
		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;
	}
}

C++: #include <stdio.h>

void main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

}