Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}

C++: //47
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int rest=1000-n;
    int coin[]={500,100,50,10,5,1};
    int ans=0;
    for(int i=0;i<6;i++){
      ans+=rest/coin[i];
      rest%=coin[i];
    }
    cout<<ans<<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;
ans=ans+n/500;
n=n%500;

ans=ans+n/100;
n=n%100;

ans=ans+n/50;
n=n%50;

ans=ans+n/10;
n=n%10;

ans=ans+n/5;
n=n%5;
ans=ans+n;
cout<<ans<<endl;
}
	return 0;
}

C++: #include<stdio.h>

int main(){
int n,c;
while(1){

scanf("%d",&n);
if(n==0)break;
c=0;
n=1000-n;
do{
if(n>=500){n=n-500;c++;}
else if(n>=100){n=n-100;c++;}
else if(n>=50){n=n-50;c++;}
else if(n>=10){n=n-10;c++;}
else if(n>=5){n=n-5;c++;}
else if(n>=1){n=n-1;c++;}
}while(n!=0);
printf("%d\n",c);
}
return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==0){
			break;
		}
		if(price>=500){
			price=price-500;
			coin ++;
		}
		else if(price>=100){
			price=price-100;
			coin++ ;
		}
		else if(price>=50){
			price=price-50;
			coin++ ;
		}
		else if(price>=10){
			price=price-10;
			coin++ ;
		}
		else if(price>=5){
			price=price-5;
			coin++ ;
		}
		else if(price>=1){
			price=price-1;
			coin++ ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

C++: #include <stdio.h>

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
  return -1;
}

C++: #include <iostream>
#include <climits>
using namespace std;
int main() {
    int coin[] = {1,5,10,50,100,500};
    int dp[1000];
    fill_n(dp, 1000, INT_MAX);
    dp[0] = 0;
    for (int i=1; i<1000; ++i) {
        for (int j=0; j<6; ++j) {
            if (i - coin[j] >= 0) {
                dp[i] = min(dp[i], dp[i-coin[j]]+1);
            }
        }
    }

    int n;
    while (cin >> n && n!=0) {
        cout << dp[1000-n] << endl;
    }

    return 0;
}

C++: #include<stdio.h>
int main()
{
	int n,r;
	while(scanf("%d",&n),n)
	{
		n=1000-n;r=n/500;r+=(n%=500)/100;r+=(n%=100)/50;r+=(n%=50)/10;r+=(n%=10)/5;r+=(n%=5);
		printf("%d\n",r);
	}
	return 0;
}

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
    int a[6], sum[6] = { 0 };
    int i = 0;
    while(a[i]) {
        std::cin >> a[i];
        if (a[i] == 0) {
            break;
        }
        i++;
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

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

using namespace std;


    int main(){
        int price=0,money[6]={500,100,50,10,5,1},ret=0,cnt;
        while(1){
        cnt=0;
        cin>>price;
        ret=1000-price;
        if(price==0)break;
        for(int i=0;i<6;i++){
                while(1){
                    if(ret<money[i])break;
                    ret-=money[i];
                    cnt++;

                }
            }

        cout<<cnt<<endl;
    }
    return 0;
}

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

int main(){
	int price,count,x,n;
	int coin[] = {500,100,50,10,5,1};
	while(cin >> n && n){
		price = 1000 - n;
		count = 0;
		for(int i = 0;i<6;i++){
			x = price / coin[i];
			count += x;
			price -= coin[i] * x; 
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
int c[]={500,100,50,10,5,1};
int cn[6];

int main(){
	int a;
	cin>>a;
	while(a){
		a=1000-a;
		FOR(i,0,6){
			cn[i]=a/c[i];
			a-=cn[i]*c[i];
		}
		int ans=0;
		FOR(i,0,6)ans+=cn[i];
		cout<<ans<<endl;
		cin>>a;
	}

	
	return 0;
}

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

int coin[] = {1, 5, 10, 50, 100, 500};
int remain, in;
int main()
{
  while(cin >> in, in){
    remain = 1000 - in;
    int ans = 0;
    for(int i = 0; i < 6; i++){
      ans += remain / coin[5 - i];
      remain %= coin[5 - i];
    }
    cout << ans << endl;
  }
  return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;

   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
   }
 }
   
  return 0;
}

C++: //08-1 ?????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    bool flg = true;
    while(flg){
        int A;
        cin >> A;
        int ans = 0;
        if(A != 0){
            A = 1000 - A;
            while(A>=500){
                A -= 500;
                ans++;
            }
            while(A>=100){
                A -= 100;
                ans++;
            }
            while(A>=50){
                A -= 50;
                ans++;
            }
            while(A>=10){
                A -= 10;
                ans++;
            }
            while(A>=5){
                A -= 5;
                ans++;
            }
            while(A>=1){
                A -= 1;
                ans++;
            }
            cout << ans << endl;
        }
        else{
            flg = false;
        }

    }
    return 0;
}