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>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        cost=1000-cost;
        coin+=cost/500;
        cost%=500;
        coin+=cost/100;
        cost%=100;
        coin+=cost/50;
        cost%=50;
        coin+=cost/10;
        cost%=10;
        coin+=cost/5;
        cout<<coin<<endl;
        cin>>cost;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int score;
int use(int money, int coin){
	int ans = money / coin;
	score += ans;
	return ans;
}

int main(){
	int money;
	scanf("%d", &money);
	money = 1000 - money;
	money -= use(money, 500) * 500;
	money -= use(money, 100) * 100;
	money -= use(money, 50) * 50;
	money -= use(money, 10) * 10;
	money -= use(money, 5) * 5;
	money -= use(money, 1) * 1;
	printf("%d\n", score);
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	int a;
	int c = 0;
	int b[6] = { 500,100,50,10,5,1 };
	cin >> a;
	a = 1000 - a;
	for (int i = 0; i < 6; ++i) {
		if (a / b[i] >= 1) {
			c = c + a / b[i];
			a = a%b[i];
		}
	}
	cout << c << endl;
	return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(void){
   while(true){
       int a;
       cin>>a;
       if(a==0) break;
       else{
           int s=0;
           int b;
           b=1000-a;
           if(b>=500){
               s=s+1;
               b=b-500;
           }
           s=s+b/100;
           b=b%100;
           if(b>=50){
               s=s+1;
               b=b-50;
           }
           s=s+b/10;
           b=b%10;
           if(b>=5){
               s=s+1;
               b=b-5;
           }
           s=s+b;
           cout<<s;
           cout<<endl;
       }
   }
}

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

int main() {
	int n,m,cnt;
	
	while(cin>>n){
		if(n==0)break;
		m=1000-n;
		
		for(;;){
			if(m>=500){
				m=m-500;
				//cout<<500<<endl;
				cnt++;
			}else if(m>=100&&500>m){
				m=m-100;
				//cout<<100<<endl;
				cnt++;
			}else if(m>=50){
				m=m-50;
				//cout<<50<<endl;
				cnt++;
			}else if(m>=10&&50>m){
				m=m-10;
				//cout<<10<<endl;
				cnt++;
			}else if(m<10){
				m=m-1;
				//cout<<1<<endl;
				cnt++;
			}
			if(m==0)break;
		}
		cout<<cnt<<endl;
		cnt=0;
	}
	
	return 0;
}

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

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

void solve()
{
	int ans = 0;
	for(int i=5;i>=0;i--){
		int t = a/V[i];
		a -= V[i]*t;
		ans += t;
	}
	cout << ans << endl;
}

int main()
{
	cin >> a;
	while(a){
		a = 1000-a;
		solve();
		cin >> a;
	}
	return 0;
}

C++: #include<stdio.h>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;


int main(){
	int n,ans;
	int m[]={500,100,50,10,5,1};
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		ans=0;
		n=1000-n;
		rep(i,6)while(m[i]<=n){
			ans++;
			n-=m[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main(){
    int N;
    scanf("%d",&N);
    N=1000-N;
    int ans=0;
    for(int i=0;i<6;i++){
        ans+=N/coin[i];
        N%=coin[i];
    }
    printf("%d\n",ans);
    return 0;
}

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

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

int main()
{
	int p;
	while (cin >> p, p!=0)
	{
		int chg = 1000 - p;
		int c=0, cnt=0;
		while (c < 6)
		{
			while (1)
			{
				if (chg-cost[c] >= 0) { cnt++; chg-=cost[c]; }
				else break;
			}
			c++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
  int p, cnt;
  while (cin >> p) {
    if (p == 0) {
      break;
    }
    cnt = 0;
    int otsu = 1000 - p;
    if (otsu >= 500) {
      otsu -= 500;
      cnt++;
    }

    if (otsu >= 100) {
      cnt += otsu / 100;
      otsu -= otsu / 100 * 100;
    }

    if (otsu >= 50) {
      cnt += otsu / 50;
      otsu -= otsu / 50 * 50;
    }

    if (otsu >= 10) {
      cnt += otsu / 10;
      otsu -= otsu / 10 * 10;
    }

    if (otsu >= 5) {
      cnt += otsu / 5;
      otsu -= otsu / 5 * 5;
    }
    if (otsu >= 1) {
      cnt += otsu;
    }
    cout << cnt << endl;
  }
}

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		n = 1000-n;
		int ans = 0;
		int m[6] = {500, 100, 50, 10, 5, 1};
		for(int i=0; i<6; i++){
			ans += n/m[i];
			n %= m[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()

using namespace std;

const vector<int> coin = {500, 100, 50, 10, 5, 1};

signed main(){
	while(true) {
		int n; cin >> n;
		if(n == 0) break;
		n = 1000 - n;
		int ans = 0;
		for(auto e : coin) {
			while(n >= e) {
				ans += 1;
				n -= e;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

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

int main() {

	int change, coin;
	cin >> 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 n;
  while(cin>>n,n){
int p=1000,s=0;
  p-=n;
  s+=p/500;
  p%=500;
  s+=p/100;
  p%=100;
  s+=p/50;
  p%=50;
  s+=p/10;
  p%=10;
  s+=p/5;
  p%=5;
  s+=p/1;
  p%=1;
  cout<<s<<endl;}

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        int Sum = 1000 - N;
        int C[] = {500, 100, 50, 10, 5, 1};
        int Res = 0;
        int i = 0;
        while (Sum > 0) {
            Res += Sum/C[i];
            Sum %= C[i];
            ++i;
        }
        cout << Res << endl;
    }

    return 0;
}

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