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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

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

    while(true) {
        int price; cin >> price;
        if (price == 0) break;
        int change = 1000 - price;
        int ans = 0;
        for (int c : coins) {
            int n = change / c;
            ans += n;
            change -= c * n;
        }
        cout << ans << "\n";
    }

    return 0;
}

C++: // AOJ 0521
#include<cstdio>
#define rep(i,a) for( int i = 0; i != (a); ++i )

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

int main()
{
	int p;
	while( scanf( "%d", &p ), p )
	{
		p = 1000-p;

		int ans = 0;
		rep( i, 6 )
			ans += p/C[i], p %= C[i];

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

	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>

using namespace std;

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

C++: #include <iostream>
using namespace std;
int count(int x, int c){
    if(x >= 500){
        return count(x-500, c+1);
    }
    if(x >= 100){
        return count(x-100, c+1);
    }
    if(x >= 50){
        return count(x-50, c+1);
    }
    if(x >= 10){
        return count(x-10, c+1);
    }
    if(x >= 5){
        return count(x-5, c+1);
    }
    if(x == 0){
        return c;
    }
    else {
        return count(x-1,c+1);
    }
}

int main (void){
    int x;
    while (true){
        cin >> x;
        if(x == 0) {
            break;
        }
        cout << count(1000 - x, 0) << endl;
    }
}

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

C++: #include<iostream>
#include<algorithm>
#include<cstring>
#define INF 1<<28
using namespace std;

int memo[10000];

int solve(int n){

  int res = INF;
  if(!n) return 0;
  if(n < 0) return INF;
  if(memo[n]) return memo[n];

  return memo[n] = res = min(res, min(solve(n-500), min(solve(n-100), min(solve(n-50), min(solve(n-10), min(solve(n-5), solve(n-1)))))) +1);
}

int main(){

  int n;
  while(cin >> n, n){
    memset(memo, 0, sizeof(memo));
    cout << solve(1000-n) << endl;
  }

}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   return 0;
}

C++: #include <iostream>
using namespace std;
int count(int x, int c){
        if(x >= 500){
            return count(x-500,c+1);
        }
        if(x >= 100){
            return count(x-100,c+1);
        }
        if(x >= 50){
            return count(x-50,c+1);
        }
        if(x >= 10){
            return count(x-10,c+1);
        }
        if(x >= 5){
            return count(x-5,c+1);
        }

        if(x == 0){
            return c;
        }
        else{
            return count(x-1,c+1);
        }
    }
int main(void){
    int x;
    while(true){
        cin >> x;
        if(x==0){
            break;
        }
        cout << count(1000-x,0)<<endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

bool check(int n){
  int k=0,x=n;
  while(x){
    k++;
    x/=10;
  }
  if(k==1){
    return true;
  }else if(k==2){
    if(n%10==n/10)return true;
  }else if(k==3){
    if(n%10==n/100)return true;
  }else if(k==4){
    if((n%10==n/1000)&&(n/10%10==n/100%10))return true;
  }
  return false;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<1000;i++){
    if(check(n-i)&&n-i>0){
      cout<<n-i<<endl;
      return 0;
    }
    if(check(n+i)&&n<10000){
      cout<<n+i<<endl;
      return 0;
    }
  }
  return 0;
}

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

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

int main(){
int s;
int a[]={500,100,50,10,5,1};
int b;
while(scanf("%d",&b),b){
	s=0;
	int c=1000-b;
	for(int d=0;d<6;d++){
		int e=c/a[d];
		s+=e;
		c-=e*a[d];
	}
	printf("%d\n",s);
}
}