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(void){
    int n,A,B,C,D,E,F,G;
    while(1){
        cin >> n;
        if(n==0)break;
        A=1000-n;
        B=(A/500);
        C=((A%500)/100);
        D=(((A%500)%100)/50);
        E=((((A%500)%100)%50)/10);
        F=(((((A%500)%100)%50)%10)/5);
        G=(((((A%500)%100)%50)%10)%5);
        cout << B+C+D+E+F+G << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int c[] = {500, 100, 50, 10, 5, 1};
    while (true) {
        cin >> n;
        if (n == 0) break;
        n = 1000 - n;
        int ans = 0;
        rep(i, 0, 6) {
            ans += n/c[i];
            n -= n/c[i] * c[i];
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(1){
	cin>>a;
    if(a=0)break;
	b=(1000-a)/500;
	c=(1000-(a+500*b))/100;
	d=(1000-(a+500*b+100*c))/50;
	e=(1000-(a+500*b+100*c+50*d))/10;
	f=(1000-(a+500*b+100*c+50*d+10*e))/5;
	g=(1000-(a+500*b+100*c+50*d+10*e+5*f))/1;
        cout<<b+c+d+e+f+g<<endl;}
	return 0;
}

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

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	if (price != 0)
	{
		while (oturi > 0)
		{
			if (oturi >= 500)
			{
				count++;
				oturi -= 500;
			}
			else if (oturi >= 100)
			{
				count++;
				oturi -= 100;
			}
			else if (oturi >= 50)
			{
				count++;
				oturi -= 50;
			}
			else if (oturi >= 10)
			{
				count++;
				oturi -= 10;
			}
			else if (oturi >= 5)
			{
				count++;
				oturi -= 5;
			}
			else if (oturi >= 1)
			{
				count++;
				oturi -= 1;
			}
		}	
	}

	cout << count;

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  while(cin >> t,t){
  int ans = 0;
  int t500 = (1000 - t)/500;
  int t100 = (1000 - t)/100 - 5*t500;
  int t10 = (1000 - t)/10 - t100*10 - t500*50; 
  ans = t500 + t100 + t10;
  if((1000 - t)%10 != 0)ans++;
  cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
	int a, b, c500, c100, c50, c10, c5, c1, sum = 0;
	cin >> a;

	while (1)
	{
		if (a == 0)
		{
			break;
		}

		b = 1000 - a;
		c500 = b / 500;
		b = b % 500;
		c100 = b / 100;
		b = b % 100;
		c50 = b / 50;
		b = b % 50;
		c10 = b / 10;
		b = b % 10;
		c5 = b / 5;
		b = b % 5;
		c1 = b / 1;

		sum = c500 + c100 + c50 + c10 + c5 + c1;
		cout << sum<<endl;
		cin >> a;
	}
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
}
return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	if (price != 0)
	{
		while (oturi > 0)
		{
			if (oturi >= 500)
			{
				count++;
				oturi -= 500;
			}
			else if (oturi >= 100)
			{
				count++;
				oturi -= 100;
			}
			else if (oturi >= 50)
			{
				count++;
				oturi -= 50;
			}
			else if (oturi >= 10)
			{
				count++;
				oturi -= 10;
			}
			else if (oturi >= 5)
			{
				count++;
				oturi -= 5;
			}
			else if (oturi >= 1)
			{
				count++;
				oturi -= 1;
			}
		}
		
		cout << count << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int coin[6] = {500,100,50,10,5,1};

int main(){
	int money, price;
	while(cin >> price){
		if(price==0) break;
		money = 1000-price;
		int count=0;
		for(int i=0; i<6; i++)
			while(money>=coin[i]) {count++; money-=coin[i];}
		cout << count << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int gohyaku,hyaku,gozyu,zyu,go,ichi;
	int dai,otsuri,mai;
	scanf("%d",&dai);
	while(dai!=0){
		otsuri=1000-dai;
		gohyaku=0;
		hyaku=0;
		gozyu=0;
		zyu=0;
		go=0;
		ichi=0;
		while(otsuri!=0){
			while(otsuri>=500){
				otsuri=otsuri-500;
					gohyaku++;
			}
			while(otsuri>=100){
				otsuri=otsuri-100;
					hyaku++;
			}
			while(otsuri>=50){
				otsuri=otsuri-50;
					gozyu++;
			}
			while(otsuri>=10){
				otsuri=otsuri-10;
					zyu++;
			}
			while(otsuri>=5){
				otsuri=otsuri-5;
					go++;
			}
			while(otsuri>=1){
				otsuri=otsuri-1;
					ichi++;
			}
			mai=gohyaku+hyaku+gozyu+zyu+go+ichi;
			printf("%d\n",mai);
			scanf("%d",&dai);
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

int main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n", ans);
}

C++: #include <iostream>
using namespace std;
int count(int x, int c){
    if(x >= 500){
        return count(x-500, c+1);
    }
    if(x >= 100){
        return count(x-100, c+1);
    }
    if(x >= 50){
        return count(x-50, c+1);
    }
    if(x >= 10){
        return count(x-10, c+1);
    }
    if(x >= 5){
        return count(x-5, c+1);
    }
    if(x == 0){
        return c;
    }
    else {
        return count(x-1,c+1);
    }
}

int main (void){
    int x;
    while (true){
        cin >> x;
        if(x == 0) {
            break;
        }
        cout << count(1000 - x, 0) << endl;
    }
}