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 <stdio.h>

int main(void)
{
	int num;
	int ans;
	int price;
	
	while (1){
		scanf("%d", &price);
		
		if (price == 0)break;
		
		price = 1000 - price;
		
		ans = 0;
		while (price){
			if (price - 500 >= 0){
				price -= 500;
				ans++;
			}
			else if (price - 100 >= 0){
				price -= 100;
				ans++;
			}
			else if (price - 50 >= 0){
				price -= 50;
				ans++;
			}
			else if (price - 10 >= 0){
				price -= 10;
				ans++;
			}
			else if (price - 5 >= 0){
				price -= 5;
				ans++;
			}
			else if (price - 1 >= 0){
				price -= 1;
				ans++;
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int dp[1005];
int c[6] = {1, 5, 10, 50, 100, 500};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int x;
  fill(dp, dp + 1005, 0x3f3f3f3f);
  dp[0] = 0;
  for (int i = 1; i <= 1000; i++) {
    for (int j = 0; j < 6; j++) {
      if (i - c[j] >= 0)
        dp[i] = min(dp[i], dp[i - c[j]] + 1);
    }
  }
  while (true) {
    cin >> x;
    if (x == 0)
      break;
    x = 1000 - x;
    cout << dp[x] << endl;
  }
}

C++: #include <iostream>

int main() {
	int a = 0,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;

	return 0;


}

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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int sum=0;
    int x;
    int cnt=0;
    while(1){
        cin>>x;
        if(!x)
            return 0;
        sum=1000-x;
        while(sum>0){
            if(sum>=500){
                cnt++;
                sum-=500;
            }
            else if(sum>=100){
                cnt++;
                sum-=100;
            }
            else if(sum>=50){
                cnt++;
                sum-=50;
            }
            else if(sum>=10){
                cnt++;
                sum-=10;
            }
            else if(sum>=5){
                cnt++;
                sum-=5;
            }
            else{
                cnt++;
                sum-=1;
            }
        }
        cout<<cnt<<endl;
        cnt=0;
    }


    return 0;
}

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

//#define PI 3.141592653589

using namespace std;



int main()
{
	int price;
	int change;
	int num;		//おつりの枚数
	
	while (1)
	{
		cin >> price;
		if (price == 0) break;
		change = 1000 - price;
		num = 0;
		num += change / 500;
		change %= 500;
		num += change / 100;
		change %= 100;
		num += change / 50;
		change %= 50;
		num += change / 10;
		change %= 10;
		num += change / 5;
		change %= 5;
		num += change / 1;
		cout << num << endl;
	}
	
	return 0;
}

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

int main(){

  int n,count;

  while(cin >> n, n){

    count = 0;
    n = 1000 - n;

    if(n >= 500){
      count++;
      n -= 500;
    }

    while(n >= 100){
      count++;
      n -= 100;
    }

    while(n >= 50){
      count++;
      n -= 50;
    }

    while(n >= 10){
      count++;
      n -= 10;
    }

    while(n >= 5){
      count++;
      n -= 5;
    }

    cout << n+count << endl;

  }
}

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

using namespace std;

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

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] * (change / coin[i]);
		}

		cout << cnt << endl;
	}

	return (0);
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

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

int main(){
	int n;
	while(scanf("%d",&n)&&!n){
		int m=1000-n;
		int res=0;
		for(int i=0;i<6;i++){ res+=m/c[i]; m%=c[i]; }
		printf("%d\n",res);
	}
}

C++: #include<stdio.h>

int main(){
	int i=0,a,b[6]={500,100,50,10,5,1},c=0;
	scanf("%d",&a);
	a=1000-a;
	while(a!=0){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}

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

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

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

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

int a, c;

main(){
    while (cin >> a){
        if (a == 0)return 0;
        a = 1000 - a, c = 0;
        int b[6] = {500, 100, 50, 10, 5, 1};
        for (int i = 0; i < 6 && a > 0; i++){
            while (a >= b[i])a -= b[i], c++;
        }
        cout << c << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int x ;
  while(1){
    cin >> x ;
    int total = 0;
    if( x==0 )break;
    int yen500 = 0;
    int yen100 = 0;
    int yen50 = 0;
    int yen10 = 0;
    int yen5 = 0;
    int yen1 = 0;
    x = 1000- x;
    yen500 = x /500 ;
    x = x%500;
    yen100 = x /100;
    x = x%100;
    yen50 = x / 50 ;
    x = x %50;
    yen10 = x/10;
    x = x%10;
    yen5 = x/5;
    x = x%5;
    yen1 = x;
    total = yen500 + yen100 + yen50 + yen10 + yen1 + yen5;
    cout << total << endl;
  }
}