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(){
	int n;
	cin >> n;
	cout << (1000-n)/500+(1000-n)%500/100+(1000-n)%500%100/50+(1000-n)%500%100%50/10+(1000-n)%500%100%50%10/5+(1000-n)%500%100%50%10%5 <<endl;
	return 0;
}

C++: #include <iostream>

int main() {
	int a,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;




}

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

int main(){
  int cost, count=0;
  cin>>cost;
  cost=1000-cost;
  while(cost>=500)count++,cost-=500;
  while(cost>=100)count++,cost-=100;
  while(cost>=50)count++,cost-=50;
  while(cost>=10)count++,cost-=10;
  while(cost>=5)count++,cost-=5;
  while(cost>=1)count++,cost-=1;
  cout<<count<<endl;
  return 0;
}

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

int nedan;
int oturi;
int maisuu = 0;
int i;
	

 int main(){
	cin >> oturi;
	i = 1000 - oturi;
	for(i=0 ; i<1000; )
	{
		if(nedan<500)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<100)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<50)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<10)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<5)maisuu+=1;
	}
	for(i=0 ; i<1000; ){
		if(nedan<1)maisuu+=1;
	}
	 return 0;
 }

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	int m;
	while(cin>>m,m){
    	int c[]={1,5,10,50,100,500};
    	m=1000-m;
    	int ans=0;
    	for(int i=5;i>=0;i--){
    		ans+=m/c[i];
    		m%=c[i];
    	}
    	cout<<ans<<endl;
	}
}

C++: #include <iostream>

int main(){
    while(true){
        int N;
        std::cin >> N;
        
        if(N == 0){
            break;
        }
        
        N = 1000 - N;
        
        int count = 0;
        
        count += N / 500;
        N %= 500;
        count += N / 100;
        N %= 100;
        count += N / 50;
        N %= 50;
        count += N / 10;
        N %= 10;
        count += N / 5;
        N %= 5;
        count += N / 1;
        N %= 1;
        
        std::cout << count << std::endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0;

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	int j = (s - s % 500)/500;
        count += j;
	s -= j*500;
        j = (s - s % 100)/100;
        count += j;
	s -= j*100;
        j = (s - s % 100)/100;
        count += j;
	s -= j*50;
        j = (s - s % 50)/50;
        count += j;
	s -= j*10;
        j = (s - s % 10)/10;
        count += j;
	s -= j*10;
        j = (s - s % 5)/5;
        count += j;
	s -= j*5;
        count += s;

	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	while(1){
		int tnok, yj;
		cin >> tnok;
		if (tnok == 0){
			return 0;
		}
		tnok = 1000 - tnok;
		if(tnok >= 500){
			yj = 1;
			tnok = tnok - 500;
		} else {
			yj = 0;
		}
		if(tnok >= 400){
			yj = yj + 4;
			tnok = tnok - 400;
		}
		else if(tnok >= 300){
			yj = yj + 3;
			tnok = tnok - 300;
		}
		else if(tnok >= 200){
			yj = yj + 2;
			tnok = tnok - 200;
		}
		else if(tnok >= 100){
			yj = yj + 1;
			tnok = tnok - 100;
		}
		if(tnok >= 50){
			yj = yj + 1;
			tnok = tnok - 50;
		}
		if(tnok >= 40){
			yj = yj + 4;
			tnok = tnok - 40;
		}
		else if(tnok >= 30){
			yj = yj + 3;
			tnok = tnok - 30;
		}
		else if(tnok >= 20){
			yj = yj + 2;
			tnok = tnok - 20;
		}
		else if(tnok >= 10){
			yj = yj + 1;
		tnok = tnok - 10;
		}
		if(tnok >= 5){
			yj = yj + 1;
			tnok = tnok - 5;
		}
		cout << tnok + yj <<endl;
	}
}

C++: g#include <iostream>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int change = 1000 - n;
        int count = 0;
        if (change >= 500) {
            change -= 500;
            count++;
        } 
        if (change >= 100) {
            int coin_100 = change / 100;
            change -= 100 * coin_100;
            count += coin_100;
        } 
        if (change >= 50) {
            change -= 50;
            count++;
        }
        if (change >= 10) {
            int coin_10 = change / 10;
            change -= 10 * coin_10;
            count += coin_10;
        }
        if (change >= 5) {
            change -= 5;
            count++;
        }
        count += change;
        cout << count << endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

int main(void)
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		int cnt = 0;
		int o = 1000 - n;
		
		while(o >= 500){
			cnt++;
			o -= 500;
		}
		while(o >= 100){
			cnt++;
			o -= 100;
		}
		while(o >= 50){
			cnt++;
			o -= 50;
		}
		while(o >= 10){
			cnt++;
			o -= 10;
		}
		while(o >= 5){
			cnt++;
			o -= 5;
		}
		while(o >= 1){
			cnt++;
			o -= 1;
		}
		printf("%d\n", cnt);
	}
	
	return (0);
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num = 0;
	while (cin >> pay)

	{
		if (!pay) break;

		pay = 1000 - pay;
		if (pay / 500 == 1){
			pay -= 500;
			num++;
		}
		for (;;){
			if (pay / 100 >= 1){
				pay -= 100;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 50 >= 1){
				pay -= 50;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 10 >= 1){
				pay -= 10;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 5){
				pay -= 5;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 1){
				pay -= 1;
				num++;
			}
			else break;
		}
		cout << num << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		if (b >= 500)
		{
			b = b - 500;
			c++;
		}
		else if (b >= 100)
		{
			b = b - 100;
			c++;
		}
		else if (b >= 50)
		{
			b = b - 50;
			c++;
		}
		else if (b >= 10)
		{
			b = b - 10;
			c++;
		}
		else if (b >= 5)
		{
			b = b - 5;
			c++;
		}
		else if (b >= 1)
		{
			b = b - 1;
			c++;
		}
		cout << c << endl;
	}	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;
const int value[6] = {1, 5, 10, 50, 100, 500};
void pay(int n) {
    int rest = 1000 - n;
    int ans = 0;
    for (int i = 5; i >= 0; i--) {
        ans += (rest / value[i]);
        rest -= rest / value[i] * value[i];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        pay(n);
    }
    return 0;
}