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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int n;
	while(scanf("%d",&n),n){
		n = 1000 - n;
		int cnt = 0;
		if(500 <= n){
			n -= 500;
			cnt++;
		}
		if(100 <= n){
			cnt += n / 100;
			n %= 100;
		}
		if(50 <= n){
			cnt += n / 50;
			n %= 50;
		}
		if(10 <= n){
			cnt += n / 10;
			n %= 10;
		}
		if(5 <= n){
			cnt += n / 5;
			n %= 5;
		}
		cnt += n;
		printf("%d\n",cnt);
	}
    return 0;
}

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

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

int main() {

	int change, coin;
	cin >> change;
	change = 1000 - change;

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

	return 0;
}

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

int main(){
int s=0;
int a[]={500,100,50,10,5,1};
int b;
while(scanf("%d",&b),b){
	int c=1000-b;
	for(int d=0;d<6;d++){
		int e=c/a[d];
		s+=e;
		b-=e*a[d];
	}
	printf("%d\n",s);
}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

int main(){
  int n;
  int coin[6]={500,100,50,10,5,1};
  while(cin>>n){
    if(n==0)break;
    n=1000-n;
    int cnt=0;
    for(int i=0;i<6;){
      if(n>=coin[i]){
	n-=coin[i];
	cnt++;
	//cout<<coin[i]<<endl;
      }else{
	i++;
      }
    }
    cout<<cnt<<endl;
  }
  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;
	*/
	
	//おつり
	int onum;
while(true){
		int N;
		cin >> N;
		if(N == 0) break;
		onum=0;
		int oturi = 1000-N;
		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>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){

	while(1){
		int a; cin >> a;
		if(a == 0) return 0;
		a = 1000 - a;

		int ans = 0;

		ans += a/500;
		a %= 500;
		ans += a/100;
		a %= 100;
		ans += a/50;
		a %= 50;
		ans += a/10;
		a %= 10;
		ans += a/5;
		a %= 5;
		ans += a;

		cout << ans << endl;
	}

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	int ans;
	while(true){
		cin >> N;
		if(N == 0)break;
		N = 1000 - N;
		ans = 0;
		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;
	}

	return 0;
}

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

int main()
{
	int x;
	int i;

	

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        int v = 1000 - n;
        int coins[] = {500, 100, 50, 10, 5, 1};
        int pos = 0, ans = 0;
        while(v > 0)
        {
            while(v - coins[pos] < 0) pos++;
            v -= coins[pos];
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  int n,ans;
  int m[6]={500,100,50,10,5,1};
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    ans=0;
    n=1000-n;
    for(int i=0;i<6;i++){
      ans+=n/m[i];
      n%=m[i];
    }
    printf("%d\n",ans);
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int coin[]={500,100,50,10,5,1};
int main()
{
	int n;
	while(scanf("%d",&n)&&n){
		int ans=0;
		n=1000-n;
		for(int i=0;i<6;i++){
			ans+=n/coin[i];
			n%=coin[i];
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

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

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

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

int main(){
	int many=0,ans=0,count=0;
	
	cin >> many ;
	ans=1000-many;
	count+=ans/500;ans=ans%500;
	count+=ans/100;ans=ans%100;
	count+=ans/50;ans=ans%50;
	count+=ans/10;ans=ans%10;
	count+=ans/5;ans=ans%5;
	count+=ans/1;ans=ans%1;
	
	printf("%d\n",count);
}