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>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007




int main(){
	int n;
	while(cin >> n && n > 0){
		n = 1000 - n;
		int ans = 0;
		ans += n / 500;
		n %= 500;
		ans += n / 100;
		n %= 100;
		ans += n / 50;
		n %= 50;
		ans += n / 10;
		n %= 10;
		ans += n /5;
		n %= 5;
		ans += n / 1;
		cout<<ans<<endl;
	}
}

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()
{
  while(cin >> n, 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 <bits/stdc++.h>

using namespace std;

int main()
{
    int M;
    while (cin >> M, M) {        
        int res = 0;
        const int coin[] = {500, 100, 100, 50, 10, 5, 1};
        M = 1000 - M;
        for (int i = 0; i < 7; i++) {
            while (M >= coin[i]) {
                M -= coin[i];
                res++;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

typedef long long ll;
using namespace std;

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

	while(true){
		int a; cin >> a;
		if(a == 0) break;
		a = 1000 - a;

		int ans = 0;
		ans += a/500;
		a %= 500;
		ans += a/100;
		a %= 100;
		ans += a/50;
		a %= 50;
		ans += a/10;
		a %= 10;
		ans += a/5;
		a %= 5;
		ans += a;

		cout << ans << endl;
	}

	return 0;

}

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

int main()
{
  int n;
  while(cin>>n && n){
    int res = 0;
    n = 1000 - n;
    res += n / 500; n %= 500;
    res += n / 100; n %= 100;
    res += n / 50;  n %= 50;
    res += n / 10;  n %= 10;
    res += n / 5;   n %= 5;
    res += n / 1;   n %= 1;

    cout<<res<<endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==1){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

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

int main()
{
while(true) {
int n;
scanf("%d", &n);
if(n == 0)
break;
int change = 1000 - n;
int ans = 0;
for(int digit = 1; digit < 1000; digit *= 10) {
int cur = change / digit % 10;
ans += (cur / 5) + (cur % 5);
}
printf("%d\n", ans);
}
return 0;
}

C++: /**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:33

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){

                int yen = 0;
                int oturi =0;
                int count = 0;

                cin >> yen;
                if(yen == 0)break;
                oturi = 1000 - yen;

                while(oturi/500 != 0){
                        oturi = oturi -500;
                        count++;        
                }
        

                while(oturi/100 != 0){
                        oturi = oturi -100;
                        count++;
                }
        

                while(oturi/50 != 0){
                        oturi = oturi -50;
                        count++;
                }
        

                while(oturi/10 != 0){
                        oturi = oturi -10;
                        count++;
                }
        

                while(oturi/5 != 0){
                        oturi = oturi -5;
                        count++;
                }
        

                count = count + oturi;        

                cout << count <<endl;

        }
    

        return 0;    


}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    while( cin >> money, money ){

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    while (cin >> n && n) {
        int cost = 1000 - n;
        int n1 = cost / 500;
        cost -= 500 * (cost / 500);
        int n2 = cost / 100;
        cost -= 100 * (cost / 100);
        int n3 = cost / 50;
        cost -= 50 * (cost / 50);
        int n4 = cost / 10;
        cost -= 10 * (cost / 10);
        int n5 = cost / 5;
        cost -= 5 * (cost / 5);
        cout << n1 + n2 + n3 + n4 + n5 + cost << '\n';
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu;
  
  cin >> money;
  oturi = 1000 - money;

  for(int i = 1000;oturi > 0;i / 10){
    oturi %= i;
    if(oturi >= i/10){
      oturi / (i/10) >= 5 ? maisu += oturi / (i/10) - 4 : maisu += oturi / (i/10);
    }
  }
    cout << maisu << endl;
    
    return 0;
  }