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

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

int main() {
	int n,a,i=0;
	cin>>n;
	a=1000-n;
	if(a>=500){
		i+=1;
		a-=500;
	}
	if(a>=100){
		int b=a/100;
		i+=b;
		a-=100*b;
	}
	if(a>=50){
		i+=1;
		a-=50;
	}
	if(a>=10){
		int b=a/10;
		i+=b;
		a-=10*b;
	}
	if(a>=5){
		i+=1;
		a-=5;
	}
	if(a>=1)
		i+=a;
	cout<<i<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        int ans = 0;
        n = 1000 - n;
        for (auto & i : {500, 100, 50, 10, 5, 1}) {
            ans += n / i, n -= i * (n / i);
        }
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

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

int main()
{
  cin >> n;
  n = 1000 - n;

  int res = 0;
  rep(k, 6){
    res += n / coin[k];
    n -= n / coin[k] * coin[k];
  }

  cout << res << endl;

  return 0;
}

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

ll N;

ll solve(ll N) {
  ll M=1000-N;
  ll ans=0;
  ll a=M/500;
  M-=a*500;
  ll b=M/100;
  M-=b*100;
  ll c=M/50;
  M-=c*50;
  ll d=M/10;
  M-=d*10;
  ll e=M/5;
  M-=e*5;
  return a+b+c+d+e+M;
}
  

int main() {
  while(cin>>N) {
    if (N) cout<<solve(N)<<endl;
    else break;
  }
  return 0;
}

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

int main(){
	int price,count,x,n;
	int coin[] = {500,100,50,10,5,1};
	while(cin >> n){
		price = 1000 - n;
		count = 0;
		for(int i = 0;i<6;i++){
			x = price / coin[i];
			count += x;
			price -= coin[i] * x; 
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

int main(){

  while(1){


  int ans = 0;

  int n;

  scanf("%d",&n);

  if(n == 0) break;

  n = 1000 - n;

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

  for(int i = 0;i < 6;i++){
    if(n == 0) break;
    ans += n / k[i];
    n = n % k[i];
  }

  printf("%d\n",ans);

  }

  return 0;

}

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

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    n = 1000 - n;
    int ans = 0;
    for (int i = 0; i < 6; ++i) {
      ans += n / c[i];
      n %= c[i];
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main()
{
	int x;
	int i = 0;

	scanf("%d", &x);

	x = 1000 - x;

	while (x >= 500 ) {
		i++;
		x -= 500;
	}
	while (x >= 100 ) {
		i++;
		x -= 100;
	}
	while (x >= 50 ) {
		i++;
		x -= 50;
	}
	while (x >= 10 ) {
		i++;
		x -= 10;
	}
	while (x >= 5 ) {
		i++;
		x -= 5;
	}
	while (x >= 1 ) {
		i++;
		x -= 1;
	}

	printf("%d\n", i);
	return (0);
}

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

int main(){

  int sum;
  int cash;

  while(cin >> cash , cash){
    cash = 1000-cash;
    sum = 0;
    sum += cash/500; cash%=500;
    sum += cash/100; cash%=100;
    sum += cash/50; cash%=50;
    sum += cash/10; cash%=10;
    sum += cash/5; cash%=5;
    sum += cash/1;
    
    cout<< sum << endl;
  }

  return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (oturi >= a[i]){
			div_t d;

			d = div(oturi, a[i]);
			oturi = oturi - a[i] * d.quot;
			count = count + d.quot;
		}
	}
	printf("%d\n",count);

	return 0;

	div(20, 3);

}

C++: #include<iostream>

using namespace std;

int main()
{
	for(;;){
	int kane, sub, cont = 0;
	
	cin >> kane;
	if(kane == 0){
		break;
	}
	
	kane = 1000 - kane;
	sub = kane;
	for(;;){
		if(sub - 500>= 0){
			cont++;
			sub -= 500;
		}
		else{
			break;
		}
	}
//	cout <<"500:" << cont << endl;
	for(;;){
		if(sub - 100 >= 0){
			cont++;
			sub -= 100;
		}
		else{
			break;
		}
	}
//	cout <<"100:" <<cont<< endl;
	for(;;){
		if(sub - 50 >= 0){
			cont++;
			sub -= 50;
		}
		else{
			break;
		}
	}
	
//	cout << "50:" << cont << endl;
	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 5 >= 0){
			cont++;
			sub -= 5;
		}
		else{
			break;
		}
	}
	
	for(;;){
		if(sub - 1 >= 0){
			cont++;
			sub -= 1;
		}
		else{
			break;
		}
	}
	
	cout << cont << endl;
}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int c[]={500,100,50,10,5,1};
int main(){
    int n;
    while(cin>>n,n){
        int ret=0,m=1000;
        while(m>n){
            rep(i,6){
                if(m-c[i]>=n){
                    m-=c[i];
                    ret++;
                    break;
                }
            }
        }
        cout<<ret<<endl;
    }
}

C++: #include<iostream>

using namespace std;

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

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

int main()
{
  int n,count;
  while(cin>>n,n){
    count=0;
    n=1000-n;
    while(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;}
    while(n>=1){count++;n-=1;}
    cout<<count<<endl;
  }
}