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 <bits/stdc++.h>
using namespace std;

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    loop {
        int N = 1000 - next<int>(), ans = 0;
        if(N == 1000) break;

        for(int coin : {500, 100, 50, 10, 5, 1}) {
            ans += N / coin;
            N %= coin;
        }

        cout << ans ln;
    }

    return 0;
}

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

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

int main(){
	int n, ans = 0;

	while(cin >> n, n){
		n = 1000 - n;

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

C++: #include <iostream>

using namespace std;

int main()
{
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0) { break; }

		n = 1000 - n;

		cout << n / 500 + (n / 100) % 5 + (n / 50) % 2 + (n / 10) % 5 + (n / 5) % 2 + n % 5 << endl;
	}

	return 0;
}

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

#define PI 4*atan(1);

int main(){
  int y;
  while(cin >> y && y){
     int b = 1000, c = 0;
    b -= y;
    for(int i = 0;; i++){
      if(b - 500 >= 0){
        b -= 500;
        c++;
        if(b == 0){
          break;
        }
      }else if(b - 100 >= 0){
        b -= 100;
        c++;
        if(b == 0){
          break;
        }
      }else if(b - 50 >= 0){
        b -= 50;
        c++;
        if(b == 0){
          break;
        }
      }else if(b - 10 >= 0){
        b -= 10;
        c++;
        if(b == 0){
          break;
        }
      }else if(b - 5 >= 0){
        b -= 5;
        c++;
        if(b == 0){
          break;
        }
      }else if(b - 1 >= 0){
        b -= 1;
        c++;
        if(b == 0){
          break;
        }
      }
    }
    cout << c << endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(a!=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 <iostream>
#include <cstdio>
using namespace std;
int main(void) {
  int V, C, sum;
  int coin[6] = {1, 5, 10, 50, 100, 500};
  while(cin >> V, V != 0) {
    sum = 0;
    C = 1000 - V;
    for(int i = 5 ; i >= 0 ; i--) {
      int t = C / coin[i];
      C -= t * coin[i];
      sum += t;
    }
    cout << sum << endl;
  }
  return 0;
}

C++: #include<stdio.h>

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

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    while(1){
        int x;
        cin >> x;
        if(x == 0)break;
        x = 1000 - x;
        
        int ans = 0;
        ans += x/500;
        x %= 500;
        ans += x/100;
        x %= 100;
        ans += x/50;
        x %= 50;
        ans += x/10;
        x %= 10;
        ans += x/5;
        x %= 5;
        ans += x;
        cout << ans << endl;
    }
    return 0;
}

C++: // 2011/12/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){

	int n;
	cin >> n;

	if(n==0)
		break;

	int m = 1000-n;

	int sum = 0;

	sum += m/500;
	m %= 500;

	sum += m/100;
	m %= 100;

	sum += m/50;
	m %= 50;

	sum += m/10;
	m %= 10;

	sum += m/5;
	m %= 5;

	sum += m;

	cout << sum << endl;

	}

	return 0;
}

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

C++: #include <iostream>
using namespace std;
 
int main() {
    // your code goes here
    int n;
    while(cin >> n && n!=0){
        n=1000-n;
        int sum=0;
        int coin[]={500,100,50,10,5,1};
        for(int i=0;i<6;i++)
            while(n>=coin[i]){
                sum++;
                n-=coin[i];
            }
    cout << sum << endl;
    }
    return 0;
}

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

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

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int x=0;
	int s[6]={500,100,50,10,5,1};
	cin>>n;
	
	n=1000-n;
	int k=0;
	while(n>0){
		if(n-s[k]>=0){
			n=n-s[k];
			x++;
		}
		else
			k++;
	}
	
	cout<<x<<endl;
	

}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  while (1) {
    int in;
    cin >> in;
    if (in == 0) break;
    int n = 1000 - in;

    int c = 0;
    c += n / 500;
    n %= 500;

    c += n / 100;
    n %= 100;

    c += n / 50;
    n %= 50;

    c += n / 10;
    n %= 10;

    c += n / 5;
    n %= 5;

    c += n / 1;
    n %= 1;

    println(str(c));
  }
  return 0;
}

C++: #include <stdio.h>
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  n=1000-n;
  ans+=n/500;
  n%=500;
  ans+=n/100;
  n%=100;
  ans+=n/50;
  n%=50;
  ans+=n/10;
  n%=10;
  ans+=n/5;
  printf("%d\n",ans+n%5);
  
}