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>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num_answer = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

	}
	

	for (int i = 0; i < j;++i) {
		cost_return = 1000 - cost_input[i];
		num_answer = 0;

		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1)
		{
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}

		CO num_answer E
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,count = 0,oturi[1000] = {};
  int money2[6] = {500,100,50,10,5,1};

  for(int i = 0;i >= 0;i++){
    cin >> money;
    count++;
    if(money == 0)
      break;
    oturi[i] = 1000 - money;
  }

  for(int j = 0;j < count;j++){
    int maisu = 0;
    for(int i = 0;i < 6;i++){
      maisu += oturi[j] / money2[i];
      oturi[j] %= money2[i];
    }
    if(maisu > 0)
      cout << maisu << endl;
  }
    return 0;
  }

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

int main() {
    const int coin[] = { 500, 100, 50, 10, 5, 1};
    int n = 0;

    while (scanf("%d", &n)) {
        if (n == 0) return 0;
        int c = 0;
        int o = 1000 - n;
        while (o != 0) {
            for (int i = 0; i < 6; ++i) {
                if (coin[i] <= o) {
                    o -= coin[i];
                    c++;
                    break;
                }
            }
        }
        printf("%d\n", c);
    }

    return 0;
}

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

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

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

int main(){
	int cnt = 0,i = 5;
	cin >> X;
	while( X > 0 ){
		while( X >= change[i] ){
			X -= change[i];
			cnt++;
		}
		i--;
	}
	cout << cnt << endl;
	return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        coin=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;
        cost%=5;
        coin+=cost;
        cout<<coin<<endl;
        cin>>cost;
    }
}

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

int main()
{
	int m;
	int coin[6] = {500, 100, 50, 10, 5, 1};

	while (cin >> m, m){
		int cnt = 0;
		int change = 1000 - m;

		for (int i = 0; i < 6; i++){
			cnt += change / coin[i];
			change %= coin[i]; // -= coin[i] * (change / coin[i]);
		}

		cout << cnt << endl;
	}

	return (0);
}

C++: #include <iostream>

using namespace std;

int main()
{
    int x;
    int ans;
    cin >> x;
    while(x!=0) {
        x=1000-x;
        ans=0;
        ans+=x/500;
        x=x%500;
        ans+=x/100;
        x=x%100;
        ans+=x/50;
        x=x%50;
        ans+=x/10;
        x=x%10;
        ans+=x/5;
        x=x%5;
        ans+=x;
        cout << ans;
        cin >> x;
    }
    return 0;
}

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

	{
		num = 0;
		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<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

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

C++: #include <stdio.h>
int main(void){
  while(1){int n,ans=0;
  scanf("%d",&n);
  if(n==0){
      break;
  }
  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;
  printf("%d\n",ans+n%5);
  }
}

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

int  main(){
  int n;
  while(1){
  int count=0;
  cin >> n;
  if(n==0)break;
  int total = 1000-n;
  if(total >= 500){
  count+=total/500;
  total%=500;
  }

  if(total >= 100){
  count+=total/100;
  total%=100;
  }
  
  if(total >= 50){
  count+=total/50;
  total%=50;
  }

  if(total >= 10){
  count+=total/10;
  total%=10;
  }

  if(total >=  5){
  count+=total/5;
  total%=5;
  }

  if(total >=  1)
  count+=total/1;

  cout << count << endl;

  }
  return 0;
}

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

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

	cout << m << endl;

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int mo,fite,hund,fiten,ten,go,one;
    cin>>mo;
    mo=1000-mo;
    fite=mo/500;
    hund=mo%500/100;
    fiten=mo%500%100/50;
    ten=mo%500%100%50/10;
    go=mo%500%100%50%10/5;
    one=mo%500%100%50%10%5;
    //cout<<fite<<" "<<hund<<" "<<fiten<<" "<<ten<<" "<<go<<" "<<one<<"\n";
    cout<<fite+hund+fiten+ten+go+one<<"\n";
}

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int c=1000-n,ans=0;
		while(c>=500) c-=500,++ans;
		while(c>=100) c-=100,++ans;
		while(c>=50) c-=50,++ans;
		while(c>=10) c-=10,++ans;
		while(c>=5) c-=5,++ans;
		while(c>=1) c-=1,++ans;
		cout<<ans<<endl;
	}
	return 0;
}