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>
#include <cstdio>
#include <string>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int price;
	int change;
	int num;		//おつりの枚数
	
	while (1)
	{
		cin >> price;
		if (price == 0) break;
		change = 1000 - price;
		num = 0;
		num += change / 500;
		change %= 500;
		num += change / 100;
		change %= 100;
		num += change / 50;
		change %= 50;
		num += change / 10;
		change %= 10;
		num += change / 5;
		change %= 5;
		num += change / 1;
		cout << num << endl;
	}
	
	return 0;
}

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

int main(){

  int n,count;

  while(cin >> n, n){

    count = 0;
    n = 1000 - n;

    if(n >= 500){
      count++;
      n -= 500;
    }

    while(n >= 100){
      count++;
      n -= 100;
    }

    while(n >= 50){
      count++;
      n -= 50;
    }

    while(n >= 10){
      count++;
      n -= 10;
    }

    while(n >= 5){
      count++;
      n -= 5;
    }

    cout << n+count << endl;

  }
}

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

using namespace std;

int main ( void )
{
	const int m[] = { 1, 5, 10, 50, 100, 500 };
	int n;
	
	while ( cin >> n, n )
	{
		n = 1000 - n;
		int count = 0;
		for (int i = 5; i >= 0; --i)
		{
			count += n / m[i];
			n %= m[i];
		}
		cout << count << endl;
	}
	return 0;
}

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

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

	while (cin >> m, m){
		int cnt = 0;
		int change = 1000 - m;

		for (int i = 0; i < 6; i++){
			cnt += change / coin[i];
			change -= coin[i] * (change / coin[i]);
		}

		cout << cnt << endl;
	}

	return (0);
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

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

int main(){
	int n;
	while(scanf("%d",&n)&&!n){
		int m=1000-n;
		int res=0;
		for(int i=0;i<6;i++){ res+=m/c[i]; m%=c[i]; }
		printf("%d\n",res);
	}
}

C++: #include<stdio.h>

int main(){
	int i=0,a,b[6]={500,100,50,10,5,1},c=0;
	scanf("%d",&a);
	a=1000-a;
	while(a!=0){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}

C++: #include<iostream>
using namespace std;
int i, p, r, q, cnt = 0;
int c[7];
int main() {
    c[1] = 500; c[2] = 100; c[3] = 50;
    c[4] = 10;  c[5] = 5;   c[6] = 1;
    while(cin >> p) {
        if(p == 0) { break; }
        r = 1000 -p;
        while(r > 0) {
            for (i=1; i<=6; i++) {
                q = r / c[i];
                cnt = cnt + q;
                r -= c[i] * q;
                if(r==0) {break;}
            }
        }
        cout << cnt << endl;
        cnt = 0;
    }
    return 0;
}

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

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

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

int a, c;

main(){
    while (cin >> a){
        if (a == 0)return 0;
        a = 1000 - a, c = 0;
        int b[6] = {500, 100, 50, 10, 5, 1};
        for (int i = 0; i < 6 && a > 0; i++){
            while (a >= b[i])a -= b[i], c++;
        }
        cout << c << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int x ;
  while(1){
    cin >> x ;
    int total = 0;
    if( x==0 )break;
    int yen500 = 0;
    int yen100 = 0;
    int yen50 = 0;
    int yen10 = 0;
    int yen5 = 0;
    int yen1 = 0;
    x = 1000- x;
    yen500 = x /500 ;
    x = x%500;
    yen100 = x /100;
    x = x%100;
    yen50 = x / 50 ;
    x = x %50;
    yen10 = x/10;
    x = x%10;
    yen5 = x/5;
    x = x%5;
    yen1 = x;
    total = yen500 + yen100 + yen50 + yen10 + yen1 + yen5;
    cout << total << endl;
  }
}

C++: #include <iostream>

using namespace std;

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

int main()
{
    int inp;

    while (cin >> inp, inp) {
        int ans = 0;

        inp = 1000 - inp;
        for (int i = 0; i < 7; i++) {
            if (inp <= 0)
                break;
            else if (inp / m[i]) {
                ans += inp / m[i];
                inp = inp % m[i];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main(void){
  int coins[] = {500, 100, 50, 10, 5, 1};

  while(1){
  int ans = 0, n; cin >> n;
  if(n == 0) return 0;
  n = 1000 - n;
  for(int i=0; i < 6; i++){
    while(n >= coins[i]){
      ans++;
      n -= coins[i];
    }
  }
  cout << ans << endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	price=1000-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;
		}
	}
	if(coins!=0){
	cout<<coin<<endl;
	}
	return 0;

}

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

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

C++: #include <iostream>

using namespace std;

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

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

        int r = 1000 - m;
        int sum = 0;
        for( auto const& c : cset ) {
            for(;;) {
                if ( r - c >= 0 ) {
                    ++sum;
                    r -= c;
                } else {
                    break;
                }
            }
        }
        cout << sum << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
 <url:>
 ?????????============================================================
 ??????????????????JOI?????¨?????§?????????????????????
 JOI?????¨???????????¬??¨???500??????100??????50??????10??????5??????1?????????????????°???????????????
 ????????????????????°????°??????????????????????????????????????????????????????????
 ????????????JOI?????¨?????§????????????????????¬?????§1000?????????1??????????????????
 ???????????????????????????????????¬??¨????????°????±???????????????°????????????????????????
 =================================================================
 ?§£??¬=============================================================
 ????????????
 ================================================================
 */

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    int K[6] = {500,100,50,10,5,1};
    while(cin >> N,N){
        int res = 0;
        N = 1000 - N;
        for(int i = 0; i < 6;i++){
            res += N/K[i];
            N %= K[i];
        }
        cout << res << endl;
    }
    return 0;
}