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++: // 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;

}

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

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

	cout << m << endl;

	return 0;
}

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

int main() {
    while (true) {
        int input;
        cin >> input;
        if (input == 0) {
            break;
        }
        int change = 1000 - input;
        int coin = 0;
        while (change > 0) {
            if (change >= 500) {
                change -= 500;
            } else if (change >= 100) {
                change -= 100;
            } else if (change >= 50) {
                change -= 50;
            } else if (change >= 10) {
                change -= 10;
            } else if (change >= 5) {
                change -= 5;
            } else {
                change--;
            }
            coin++;
        }
        cout << coin << endl;
    }
}

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

int main()
{
int m;
while(cin>>m){
if(m==0) break;
int ans=0;
m=1000-m;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans<<endl;

}

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int n, k;
int main(){
    while(cin >> n, n){
        int res=0;
        int rest=1000-n;
        while(rest){
            if(rest-500>=0){
                res++;
                rest-=500;
                continue;
            }
            if(rest-100>=0){
                res++;
                rest -=100;
                continue;
            }
            if(rest-50>=0){
                res++;
                rest -=50;
                continue;
            }
            if(rest-10>=0){
                res++;
                rest -=10;
                continue;
            }
            if(rest-5>=0){
                res++;
                rest -=5;
                continue;
            }
            if(rest-1>=0){
                res++;
                rest -=1;
                continue;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,s,ss;
	while(1){
		scanf("%d",&a);
		if(a==0)break;
		s=1000-a;
		ss=s/500;
		s=s%500;
		ss+=s/100;
		s=s%100;
		ss+=s/50;
		s=s%50;
		ss+=s/10;
		s=s%10;
		ss+=s/5;
		s=s%5;
		ss+=s/1;
		printf("%d\n",ss);
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int coin[6] = {500,100,50,10,5,1};
	while(1){
		int in;
		cin>> in;
		if(!in) break;
		int ans=0;
		in = 1000 - in;
		for(int i=0;i<6;i++){
			int c = coin[i];
			ans += in / c;
			in = in - c*(in/c);
		}
//		assert(in==0);
		cout<< ans<< endl;
	}

	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include<stdio.h>
int main (void)
{
	int n;
	int s;
	int cnt;
	
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		s=1000-n;
		while(s>=500){
			s=s-500;
			cnt++;
		}
		while(s>=100){
			s=s-100;
			cnt++;
		}
		while(s>=50){
			s=s-50;
			cnt++;
		}
		while(s>=10){
			s=s-10;
			cnt++;
		}
		while(s>=5){
			s=s-5;
			cnt++;
		}
		while(s>=1){
			s=s-1;
			cnt++;
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        int tmp = 1000-n;

        int ans = 0;
        int money[] = {500, 100, 50, 10, 5, 1};
        rep(i, 6) {
            ans += tmp/money[i];
            tmp -= money[i]*(tmp/money[i]);
        }
        cout << ans << '\n';
    }
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n;
int a[]={500,100,50,10,5,1};

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

    while(true) {
	cin>>n;
	if(n==0) break;
	n=1000-n;
	int ans=0;
	REP(i,6) {
		if(n>=a[i]) {
			int tmp=n/a[i];
			ans+=tmp;
			n-=tmp*a[i];
		}
	}
	cout<<ans<<endl;
    }

	return 0;
}