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 <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, 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>
using namespace std;
int main(){
int a,b,c=0;
while(1){
cin>>a;
  if(a==0){
       break;
}else{
    b=1000-a;
    c=b/500;
    c=c+b%500/100;
    c=c+b%500%100/50;
    c=c+b%500%100%50/10;
    c=c+b%500%100%50%10/5;
    c=c+b%500%100%50%10&5/1;
    a=0; 
   }
cout<< c <<endl;
} 
return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/10;
	i=z%10;
	c=b+y+m;
	printf("%d\n",c);
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, sum = 0;

int main(){
	cin >> n;
	n = 1000 - n;
	sum += n / 500;
	n %= 500;
	sum += n / 100;
	n %= 100;
	sum += n / 50;
	n %= 50;
	sum += n / 10;
	n %= 10;
	sum += n / 5;
	n %= 5;
	sum += n;
	cout << sum << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>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;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<cstring>
using namespace std;
int main() {
	int N;
	scanf("%d",&N);
	int n = 1000 - N;
	int cnt = 0;
	if(500 <= n){
		n -= 500;
		cnt++;
	}
	if(100 <= n){
		cnt += n / 100;
		n %= 100;
	}
	if(50 <= n){
		cnt += n / 50;
		n %= 50;
	}
	if(10 <= n){
		cnt += n / 10;
		n %= 10;
	}
	if(5 <= n){
		cnt += n / 5;
		n %= 5;
	}
	cnt += n;
	printf("%d\n",cnt);
    return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<m<<endl;

}

}

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer[5] = { 0 };

	int in = 0, change = 0, n = 0;



	for (int j = 0; j < 5; j++) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
		answer[j] = n;
	}


	for (int j = 0; j < 5; j++) {
		if (answer[j] == 0) break;
		cout << answer[j] << endl;
	}

	return 0;
}

C++: #include <iostream>

int main(){
  int a[6] = {500,100,50,10,5,1};
  int n;
  std::cin>>n;
  n=1000-n;
  int res = 0;
  for(int i=0;i<6;i++){
    res = res + n / a[i];
    n = n % a[i];
  }
  std::cout<<res<<std::endl;
  return 0;
}

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

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

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    const vector<int> coins = {500, 100, 50, 10, 5, 1};
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int ans = 0;
        for (auto c : coins) {
            int tmp = N / c;
            ans += tmp;
            N -= tmp * c;
        }
        cout << ans << endl;
    }
}

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

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

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

C++: #include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int m,o,ans=0;
    cin >> m;
    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>5){
        ans++;
        o-=5;
    }
    ans+=o;
    cout <<ans<<endl;
    return 0;
}

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

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