Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

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

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

int main(){
	int cnt = 0,i = 5;
	cin >> X;
	while( X > 0 ){
		while( X >= change[i] ){
			X -= change[i];
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
	int x, y;
	while(scanf("%d", &x) != EOF){
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int pay=0,coin=0;
	while(cin>>pay,pay){
		coin=0;
	pay=1000-pay;
	if(pay/500>=1){
		pay-=500;
		coin++;
	}
	if(pay>=100){
		coin+=pay/100;
		pay-=100*(pay/100);
	}
	if(pay>=50){
		coin+=pay/50;
		pay-=50*(pay/50);
	}
	if(pay>=10){
		coin+=pay/10;
		pay-=10*(pay/10);
	}
	if(pay>=5){
		coin+=pay/5;
		pay-=5*(pay/5);
	}
	if(pay>=1){
		coin+=pay;
	}
	cout<<coin<<endl;
}
}

C++: #include<iostream>
using namespace std;
int main(){
  int mon,c;
  while(1){
    cin>>mon;
    if(mon==0){
      break;
    }
    mon=1000-mon;
    c=0;
    for(int i=0;i<15;i++){
      if(mon==0){
	break;
      }
      if(mon>=500){
	mon-=500;
	c++;
      }if(mon<500&&mon>=100){
	mon-=100;
	c++;
      }if(mon<100&&mon>=50){
	mon-=50;
	c++;
      }if(mon<50&&mon>=10){
	mon-=10;
	c++;
      }if(mon<10&&mon>=5){
	mon-=5;
	c++;
      }if(mon<5){
	c+=mon;
	mon=0;
      }
    }
  cout<<c<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt;
while(cin>>price){
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>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
	cin>>a;
	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<iostream>
#include<vector>
using namespace std;

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

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

int money,c[1010],n,x;
int main(){
  x=0;
  scanf("%d",&money);
  n=1000-money;
  for(int i=0;500<=n;i++){x++;n=n-500;}
  for(int i=0;100<=n;i++){x++;n=n-100;}
  for(int i=0;50<=n;i++){x++;n=n-50;}
  for(int i=0;10<=n;i++){x++;n=n-10;}
  for(int i=0;5<=n;i++){x++;n=n-5;}
  for(int i=0;1<=n;i++){x++;n=n-1;}
  printf("%d\n",x);
}

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

C++: #include<stdio.h>
int main()
{
	int n,i,coin;
	
	for(;;){
		scanf("%d",&n);
		if(n==0){break;}
		else{
			coin=0;
			n=1000-n;
			for(;n!=0;){
				if	   (n>=500){n-=500;coin++;}
				else if(n>=100){n-=100;coin++;}
				else if(n>= 50){n-= 50;coin++;}
				else if(n>= 10){n-= 10;coin++;}
				else if(n>=  5){n-=  5;coin++;}
				else if(n>=  1){n-=  1;coin++;}
			}
			printf("%d\n",coin);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

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

int main() {
    int coins[] = {500, 100, 50, 10, 5, 1};
    int price;
    while(true) {
        cin >> price;
        if (price == 0) break;

        int change = 1000 - price;
        int cnt = 0;
        for (int c : coins) {
            int v = change / c;
            cnt += v;
            change -= v * c;
        }

        cout << cnt << "\n";
    }

    return 0;
}

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

const int coins[] = { 500, 100, 50, 10, 5, 1 };

int main() {

	int change, coin;
	cin >> change;
	change = 1000 - change;

	coin = 0;
	for (int i = 0; i < 6; ++i) {
		if (change >= coins[i]) {
			coin += change / coins[i];
			change %= coins[i];
			if (!change)
				break;
		}
	}
	cout << coin << endl;

	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	int money = 0;

	int change = 0;



	while (1)
	{


		int count500 = 0;

		int count100 = 0;

		int count50 = 0;

		int count10 = 0;

		int count5 = 0;

		int count1 = 0;


		cin >> money;

		if (money == 0)break;


		change = 1000 - money;

		count500 = change / 500;

		count100 = (change - (count500 * 500)) / 100;

		count50 = (change - (count500 * 500) - (count100 * 100)) / 50;

		count10 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50)) / 10;

		count5 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10)) / 5;

		count1 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10) - (count5 * 5)) / 1;

		cout << count500 + count100 + count50 + count10 + count5 + count1 << endl;
	}

	return 0;
}

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

int main()
{

	int price, change, coin_num, cnt;
	int coin_kind[] = {500, 100, 50, 10, 5, 1};

	while(cin >> price, price > 0) {
		coin_num = 0;
		cnt = 0;
		change = 1000 - price;
		while(change > 0) {
			if(change - coin_kind[cnt] >= 0) {
				coin_num++;
				change -= coin_kind[cnt];
			}
			else {
				cnt++;
			}
		}
		cout << coin_num << endl;
	}

	return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
int n;while(true){cin>>n;if(n==0){break;}
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<endl;}}