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>
#define add(coinvalue) changecoins+=(int)change/coinvalue;change%=coinvalue;
using namespace std;

int main() {
	// your code goes here
	for(;;){
		int fee;
		cin >> fee;
		if(fee==0)
			break;
		int change=1000-fee;
		int changecoins=0;
		add(500)
		add(100)
		add(50)
		add(10)
		add(5)
		add(1)
		cout << changecoins << endl;
	}
	return 0;
}

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

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

double eps = 1e-10 ;

  template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  while(cin >> n){
    n = 1000-n;
    while(n >= 500){
      n -= 500;
      ++ans;
    }
    while(n >= 100){
      ++ans;
      n -= 100;
    }
    while(n >= 50){
      n -= 50;
      ++ans;
    }
    while(n >= 10){
      ++ans;
      n -= 10;
    }
    while(n >= 5){
      n -= 5;
      ++ans;
    }
    while(n >= 1){
      n -= 1;
      ++ans;
    }
    cout << ans<< endl;
  }
  return 0;
}

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

int main(void)
{
	int much;
	int c = 0;

	while(cin >> much, much > 0){
		much = 1000 - much;

		if(much >= 500){
			much %= 500;
			c++;
		}
		if(much >= 100){
			c += (int)(much / 100);
			much %= 100;
		}
		if(much >= 50){
			c += (int)(much / 50);
			much %= 50;
		}
		if(much >= 10){
			c += (int)(much / 10);
			much %= 10;
		}
		if(much >= 5){
			c += (int)(much / 5);
			much %= 5;
		}
		c += much;

		cout << c << endl;

	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	int n;
	while (in >> n) {
		if (!n)break;
		int a = 1000 - n,ans=0;
		int c[5] = { 500, 100, 50, 10, 5 };
		REP(i, 5) {
			ans += a / c[i];
			a %= c[i];
		}
		out << ans + a << endl;
	}
	return 0;

}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 3000
using namespace std;

int C[6]={1,5,10,50,100,500};
int T[MAX+1];
void douteki();

int main(){
  int n;
 

  while(1){
    cin >> n;
    if(n == 0)break; 
    douteki();
    cout << T[1000-n] << endl;
  }



}

void douteki(){
  for(int j=0;j<=MAX;j++)T[j]=10000;
  T[0]=0;
  for(int i=0;i<6;i++){
    for(int j=C[i];j<=MAX;j++){
      T[j]=min(T[j],T[j-C[i]]+1);
    }
  }

}

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

C++: #include<bits/stdc++.h>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main(){
    int N;
    while(scanf("%d",&N),N){
        N=1000-N;
        int ans=0;
        for(int i=0;i<6;i++){
            ans+=N/coin[i];
            N%=coin[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>

using namespace std;

int main() {

  const array<int, 6> coins = { 500, 100, 50, 10, 5, 1 };

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

    n = 1000 - n;
    int count = 0;
    for ( auto coin : coins ) {
      if ( n > coin ) {
    	count += (n / coin);
    	n %= coin;
      }
    }
    cout << count << endl;
  }
  return 0;  
}

C++: #include<iostream>

using namespace std;

int main(void){
    
    int n,otsuri,count;
    const int money[6]={1,5,10,50,100,500};

    while(cin>>n,n){
            
        otsuri=1000-n;
        count=0;
        for(int i=5;i>=0;i--){
            while(otsuri>=money[i]){
                otsuri=otsuri-money[i];
                count++;
            }   
        }   
        cout<<count<<endl;
    }   


}

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


using namespace std;
int main() {
    int V[6] =  {1, 5, 10, 50, 100, 500};
    int C[6];  //枚数
    int A;  //合計金額
    int t = 0;

    while(1) {
        cin >> A;
        if(A == 0){
            break;
        }
        A = 1000 - A;
        int ans = 0;
        for(int i = 5; i >= 0; i--){ //Vは500円から使う
            t = A / V[i]; //コインを使う枚数
            A -= t * V[i]; //A(合計金額)から支払われた分だけ引く
            ans += t;
            }
        cout << ans << '\n';
        }
    return 0;
    }

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){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}

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

int change[6]={1,5,10,50,100,500};
int cnt;
int n;

int main(){
	while(cin >> n){
		if(!n)break;
		cnt = 0;
		n = 1000-n;
		for( int i = 5; i >= 0; i-- ){
			while(n>=change[i]){
				n-=change[i];
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <stdio.h>
int change(int);
int main(void) {
  int money, mai;
  scanf("%d", &money);
  while(money != 0) {
    money = 1000 - money;
    mai = change(money);
    scanf("%d", &money);
  }
  printf("%d\n", mai);
  return 0;
}

int change (kane){
  int count = 0, i = 0;
  int wei[6] = {500, 100, 50, 10, 5, 1};
  while(kane > 0 && i < 6) {
    if((kane / wei[i]) > 0) {
      kane = kane - wei[i];
      printf("%d, %d\n", kane, i);
      count++;
    }
    i++;
  }
  return count;
}