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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int ans=0;
    while(cin>>n,n){
        ans=0;
        int hoge=1000-n;
        int a=hoge/500;
        hoge-=a*500;
        ans+=a;
        a=hoge/100;
        hoge-=a*100;
        ans+=a;
        a=hoge/50;
        hoge-=a*50;
        ans+=a;
        a=hoge/10;
        hoge-=a*10;
        ans+=a;
        a=hoge/5;
        ans+=a;
        hoge-=a*5;
        cout<<ans+hoge<<endl;
        
    }
}

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

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

int main() {
	int in;
	while(cin >> in) {
		if (in == 0) break;
		int p = 1000 - in;
		int ans = 0;
		int units[] = { 500, 100, 50, 10, 5, 1 };
		for (int i = 0; i < 6; i++) {
			ans += p /  units[i];
			p %= units[i];
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int main() {
	int dp[1000], tmp[] = { 500,100,50,10,5,1 }, n;
	fill_n(dp, 1000, INF);
	dp[0] = 0;
	for (int i = 0; i < 1000; i++) {
		for (int j = 0; j < 6; j++) {
			if (i - tmp[j] >= 0) dp[i] = min(dp[i], dp[i - tmp[j]] + 1);
		}
	}
	while (cin >> n, n) cout << dp[1000 - n] << endl;
}

C++: #include <iostream>

using namespace std;

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

    x=1000-x;
    int ans=0;
    if(x>=500){
      ans++;
      x-=500;
    }
    while(x>=100){
      ans++;
      x-=100;
    }
    if(x>=50){
      ans++;
      x-=50;
    }
    while(x>=10){
      ans++;
      x-=10;
    }
    if(x>=5){
      ans++;
      x-=5;
    }
    ans+=x;
    cout << ans << endl;
  }
  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<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	scanf("%d",&genkin);
	while(genkin!=0){
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d\n",sum);
	sum=0;
	money=1000;
	scanf("%d",&genkin);
	}
	return 0;
}

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

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

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

  while (cin >> n, n){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <fstream>

using namespace std;

const int INF = 100000000;

int main(){

	int dp[1000];
	fill(dp,dp+1000,INF);
	dp[0] = 0;

	int serve[] = {1,5,10,50,100,500};
	for(int i = 1; i < 1000; i++){
		for(int j = 0; j < 6; j++){
			if(i - serve[j] >= 0){
				dp[i] = min(dp[i],dp[i-serve[j]] + 1);
			}
			else
				break;
		}
	}

	int n;
	while(cin >> n && n != 0){
		int left = 1000 - n;
		cout << dp[left] << endl;
	}

	return 0;
}

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

int main(){
int s=0;
int a[]={500,100,50,10,5,1};
int b;
while(scanf("%d",&b),b){
	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);
}
}

C++: #include<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 5) {
				a = a - 5;
				cnt++;;
			}
			else if (a >= 1) {
				a = a - 1;
				cnt++;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

C++: #include <iostream>

using namespace std;

int main() {
	int a;
	while (cin >> a) {
		if (a == 0) {
			break;
		}
	a = 1000 - a;
	int counter = 0;
	if (a >= 500) {
		counter += a/500;
		a %= 500;
	}
	if (a >= 100) {
		counter += a/100;
		a %= 100;
	}
	if (a >= 50) {
		counter += a/50;
		a %= 50;
	}
	if (a >= 10) {
		counter += a/10;
		a %= 10;
	}
	if (a >= 5) {
		counter += a/5;
		a %= 5;
	}
	if (a >= 1) {
		counter += a;
	}
	cout << counter << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void){
    vector<int> pay;
    int coins[] = {500,100,50,10,5,1};
    while(true){
          int temp;
          cin >> temp;
          if(temp == 0)break;
          pay.push_back(temp);
    }
    
    for(int i = 0;i < pay.size();i++){
          int change = 1000 - pay[i];
          int total = 0;
          for(int j = 0;j < 6;j++){
                int n = change / coins[j];
                change -= n * coins[j];
                total += n;
          }
          cout << total << endl;
    }
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a, b;
	while(cin >> a){
		b = 1000 - a;
		int ret = 0;
		while(b != 0){
			if(b >= 500){
				ret+= b/500;
				b %= 500;
			}else if(b >= 100){
				ret += b/100;
				b %= 100;
			}else if(b >= 50){
				ret += b/50;
				b %= 50;
			}else if(b >= 10){
				ret += b/10;
				b %= 10;
			}else if(b >= 5){
				ret += b/5;
				b %= 5;
			}else{
				ret += b;
				b = 0;
			}
		}
		cout << ret << endl;
	}

	return 0;
}