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 <vector>
using namespace std;

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

  while(true){
    cin >> input;
    if(input == 0) break;
    input = 1000-input;
    int n=0;
    for(int i=0;i<6;i++){
      n+=input/c[i];
      input = input%c[i];
    }
    cout << n << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(a!=0){
	cin>>a;
	b=(1000-a)/500;
	c=(1000-(a+500*b))/100;
	d=(1000-(a+500*b+100*c))/50;
	e=(1000-(a+500*b+100*c+50*d))/10;
	f=(1000-(a+500*b+100*c+50*d+10*e))/5;
	g=(1000-(a+500*b+100*c+50*d+10*e+5*f))/1;
        cout<<b+c+d+e+f+g<<endl;}
	return 0;
}

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

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

int main(){
  int n;
  while(cin >> n,n){
    n = 1000-n;
    int pos = 0, ans = 0;
    while(n){
      if(n>=coin[pos]){
	n -= coin[pos];
	ans++;
      }else{
	pos++;
      }
    }
    cout << ans << endl;
  }
}

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

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

int main(){
    int n;
    while(cin>>n,n){
            
        n=1000-n;
        int ans=0;
    
        for(int i=0;i<6;i++){
            ans+=n/coin[i];
            n%=coin[i];
        }
        
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};

    while (scanf("%d", &amount), amount){
        int money = 1000;
        money -= amount;
        int count = 0;
        int i = 0;

        while (i < 6){
            if (money - change[i] >= 0){
                money -= change[i];
                count++;
            }
            else {
                i++;
            }
        }

        printf("%d\n", count);
    }

    return (0);
}

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[10];
	int j = 0;

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

		cost_return = 1000 - cost_input[i];
		num[i] = 0;

		if (cost_return < 5) {
			num[i] = cost_return;
			continue;
		}
		else {
			if (cost_return < 10) {
				num[i] = 1 + cost_return - 5;
				continue;
			}
		}


		if (cost_return >= 500) {
			++num[i];
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num[i];
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num[i];
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num[i];
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num[i];
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num[i];
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		
	}
	
	for (int i = 0; i < j; ++i) {
		CO num[i] E
	}

	
}

C++: #include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
int main(){
	int n;
	int change[] = {500,100,50,10,5,1};
	while(scanf("%d",&n),n){
		n = 1000-n;
		int ans = 0;
		while(n > 0){
			ans++;
			for(int i = 0; i < 6; i++){
				if(n - change[i] >= 0){
					n -= change[i];
					break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    while( cin >> money ){

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    }
    return 0;
}

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

using namespace std;

vector<int> ans;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		
		int change = 1000 - n;
		int coin[] = {500,100,50,10,5,1};
		
		int tans = 0;
		for(int i = 0;i < 6;i++){
			int maisu = change / coin[i];
			if(maisu != 0){
				tans += maisu;
				change -= coin[i] * maisu;
			}
		}
		ans.push_back(tans);
	}
	
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin >> n; n = 1000 - n;
	int r = 0;
	r += n / 500; n %= 500;
	r += n / 100; n %= 100;
	r += n / 50; n %= 50;
	r += n / 10; n %= 10;
	r += n / 5; n %= 5;
	r += n;
	cout << r << endl;
	return 0;
}

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

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt=0,div[6]=[500,100,50,10,5,1];
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 <iostream>
#include <cstdio>

using namespace std;

int main(){
	int price;
	int num[5] = {0};
	int i = 0;

	while (1){
		scanf("%d", &price);

		if (price != 0){
			price = 1000 - price;

			if (price / 500 != 0){
				num[i] += (price / 500);
				price -= (price / 500) * 500;	
			}
			if (price / 100 != 0){
				num[i] += (price / 100);
				price -= (price / 100) * 100;
			}
			if (price / 50 != 0){
				num[i] += (price / 50);
				price -= (price / 50) * 50;
			}
			if (price / 10 != 0){
				num[i] += (price / 10);
				price -= (price / 10) * 10;
			}
			if (price / 5 != 0){
				num[i] += (price / 5);
				price -= (price / 5) * 5;
			}
			if (price != 0){
				num[i] += price;
			}
			printf("%d", price);
		}
		else {
			break;
		}
		i++;
	}

	for (int i = 0; num[i] >= 1; i++){
		printf("%d\n", num[i]);
	}

}

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout<<b/500+c/100+d/50+e/10+f/5+g<<endl;
	return 0;
}

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

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

int main(){
	int n;
	while(cin >> n, n){
		ans = 0;
		n = 1000 - n;

		for(int i=0; i < 6; i++){
			ans += n / p[i];
			n -= n / p[i] * p[i];
		}
		cout << ans << endl;
	}
}