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>
using namespace std;
int main(){
int price,cnt;
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=(price%500);
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
}
return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, sum = 0;

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

C++: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

void solve(int n){
	n=1000-n;
	int ans=0;
	int c[5]={500,100,50,10,5};
	rep(i,5){
		while(n-c[i]>=0){
			ans++;
			n-=c[i];
		}
	}
	ans+=n;
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n){
		solve(n);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  for(int N; cin>>N&&N;){
    int n=1000, a=0;
    while(1) {
      if(n-500>=N) n-=500,a++;
      else if(n-100>=N) n-=100,a++;
      else if(n-50>=N) n-=50,a++;
      else if(n-10>=N) n-=10,a++;
      else if(n-5>=N)n-=5,a++;
      else if(n-1>=N)n--,a++;
      else break;
    }cout <<a<<endl;
  }
  return 0;
}

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

using namespace std;

int calcCoins(int price) {
	const int coinNums[] = {500, 100, 50, 10, 5, 1};
	int result = 0;
	int remain = price;

	for (int i = 0; i < 6; i++) {
		int coinMaisu = remain / coinNums[i];
		result += coinMaisu;
		remain -= coinMaisu * coinNums[i];
	}

	return result;
}

int main(void){
    vector<int> prices;
	while (true) {
		int price;
		cin >> price;

		if (price == 0) break;
		prices.push_back(price);
	}

	for (int i = 0; i < prices.size(); i++) {
		cout << calcCoins(1000 - prices[i]) << endl;
	}
}

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(1){
    cin >> n;
    if(n == 0){
      break ;
    }
    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;
    ans = 0;
  }
  return 0;
}

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

int nedan;
int oturi;
int maisuu = 0;
int i;
	

 int main(){
	cin >> oturi;
	i = 1000 - oturi;
	for(i=0 ; i<1000; )
	{
		if(nedan<500)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<100)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<50)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<10)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<5)maisuu+=1;
	}
	for(i=0 ; i<1000; ){
		if(nedan<1)maisuu+=1;
	}
	 return 0;
 }

C++: #include <iostream>
#include <vector>
using namespace std;
const int coin[6] = {1,5,10,50,100,500};
const int sen = 1000;
int main(){
  int n;
  while(cin >> n, n != 0){

    int oturi = sen - n;
    int sum = 0;
    int cnt = 5;
    while(oturi != 0){
      if(oturi/coin[cnt] != 0){
	sum++;
	oturi -= coin[cnt];
      }
      else{
	cnt--;
      }
    }
    cout << sum << endl;
  }
  return 0;
}

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

int main()
{
  int n;

  while(cin >> n && n != 0){
    int cnt = 0;
    n = 1000 - n;
    if (n >= 500){
      cnt++;
      n -= 500;
    }
    while (n >= 100){
      cnt++;
      n -= 100;
    }
    if (n >= 50){
      cnt++;
      n -= 50;
    }
    while (n >= 10){
      cnt++;
      n -= 10;
    }
    if (n >= 5){
      cnt++;
      n -= 5;
    }
    while (n--){
      cnt++;
    }

    cout << cnt << endl;
  }

  return 0;
}