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<algorithm>
using namespace std;
int main(){
    int n,c[6]={500,100,50,10,5,1},ans;
    while(true){
        cin>>n;
        if(!n)break;
        n=1000-n,ans=0;
        for(int i=0;i<6;i++)ans+=n/c[i],n%=c[i];
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main(){
    int N;
    while(scanf("%d",&N),N){
        N=1000-N;
        int ans=0;
        for(int i=0;i<6;i++){
            ans+=N/coin[i];
            N%=coin[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>

using namespace std;

int main() {

  const array<int, 6> coins = { 500, 100, 50, 10, 5, 1 };

  while(true) {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    n = 1000 - n;
    int count = 0;
    for ( auto coin : coins ) {
      if ( n > coin ) {
    	count += (n / coin);
    	n %= coin;
      }
    }
    cout << count << endl;
  }
  return 0;  
}

C++: #include<iostream>

using namespace std;

int main(void){
    
    int n,otsuri,count;
    const int money[6]={1,5,10,50,100,500};

    while(cin>>n,n){
            
        otsuri=1000-n;
        count=0;
        for(int i=5;i>=0;i--){
            while(otsuri>=money[i]){
                otsuri=otsuri-money[i];
                count++;
            }   
        }   
        cout<<count<<endl;
    }   


}

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


using namespace std;
int main() {
    int V[6] =  {1, 5, 10, 50, 100, 500};
    int C[6];  //枚数
    int A;  //合計金額
    int t = 0;

    while(1) {
        cin >> A;
        if(A == 0){
            break;
        }
        A = 1000 - A;
        int ans = 0;
        for(int i = 5; i >= 0; i--){ //Vは500円から使う
            t = A / V[i]; //コインを使う枚数
            A -= t * V[i]; //A(合計金額)から支払われた分だけ引く
            ans += t;
            }
        cout << ans << '\n';
        }
    return 0;
    }

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){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}

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

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

int main(){
	while(cin >> n){
		if(!n)break;
		cnt = 0;
		n = 1000-n;
		for( int i = 5; i >= 0; i-- ){
			while(n>=change[i]){
				n-=change[i];
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <stdio.h>
int change(int);
int main(void) {
  int money, mai;
  scanf("%d", &money);
  while(money != 0) {
    money = 1000 - money;
    mai = change(money);
    scanf("%d", &money);
  }
  printf("%d\n", mai);
  return 0;
}

int change (kane){
  int count = 0, i = 0;
  int wei[6] = {500, 100, 50, 10, 5, 1};
  while(kane > 0 && i < 6) {
    if((kane / wei[i]) > 0) {
      kane = kane - wei[i];
      printf("%d, %d\n", kane, i);
      count++;
    }
    i++;
  }
  return count;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007
#define MAX_H 101
#define MAX_W 101


int main(){

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


    int n;
    while(cin >> n,n){
        int count = 0;
        int change = 1000-n;
        for(int i = 0;i < 6;i++){
            while(change >= money[i]){
                count++;
                change-=money[i];
            }
        }
        cout << count << endl;
    }



    return 0;
}

C++: using namespace std;
int main(){
	int n,c; int coin[]={500,100,50,10,5,1};
	while(cin>>n,n){
		c=0,n=1000-n; for(int i=0;i<6;i++)c+=n/coin[i],n%=coin[i];
		cout<<c<<endl;
	}
	return 0;
}

C++: #include <cstdio>

int main()
{
  int n;
  while (scanf("%d", &n), n)  
  {
      int left = 1000 - n;
      int coin[] = { 500, 100, 50, 10, 5, 1 };
      int res = 0;
      for (int i = 0; left; ++i)
	  while (left >= coin[i])
	      ++res, left -= coin[i];
      printf("%d\n", res);
  }
}

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


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

	cout << m << endl;
    
    }
}

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

C++: #include <stdio.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

	return 0;

}

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout<<b/500+c/100+d/50+e/10+f/5+g<<endl;
	return 0;
}

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

int memo[1111];
int p[] = {500, 100, 50, 10, 5, 1};

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  for(int i=0;i<6;i++) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

int main(){

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

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

int main()
{
    int n;

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

    return 0;
}

C++: #include <iostream>
 
using namespace std;
 
int main()
{
	int change,money;

	while(1){
	cin>>money;
	if(money<1||money>1000){
		break;
	}else{
		int  coin,coin1,coin2,coin3,coin4,coin5,coin6;

		change=1000-money;

		coin1=change/500;
		coin2=change%500/100;
		coin3=change%500%100/50;
		coin4=change%500%100%50/10;
		coin5=change%500%100%50%10/5;
		coin6=change%500%100%50%10%5/1;

		coin=coin1+coin2+coin3+coin4+coin5+coin6;
		cout<<coin<<"\n";
	
		}
	}



    return 0;
}

C++: #include <cstdio>
using namespace std;
int main()
{
 int a;
 scanf("%d",&a);
 a=1000-a;
 printf("%d\n",a/500+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);
}