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++: #include<iostream>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << endl;
	cout << onum[1] << endl;
	cout << onum[2] << endl;
	cout << onum[3] << endl;
	cout << onum[4] << endl;
	return 0;
}

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

int main()
{
	int v[] = {500, 100, 50, 10, 5, 1};
	while (1){
		int price;
		cin >> price;
		if (price == 0) return 0;
		price = 1000 - price;
		int ans = 0;

		for (int i = 0; i < 6; i++){
			ans += price / v[i];
			price %= v[i];
		}
		cout << ans << endl;
	}

}

C++: #include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int m,o,ans;
    while(1){
    o=0;
    ans=0;
    cin >> m;
    if(m==0)break;
    o=1000-m;
    if(o>500){
        o-=500;
        ans++;
    }
    if(o / 100 > 0){
        ans+=o/100;
        o%=100;
    }
    if(o>50){
        o-=50;
        ans++;
    }
    if(o / 10 > 0){
    ans+=o/10;
    o%=10;
    }
    if(o>5){
        ans++;
        o-=5;
    }
    ans+=o;
    cout <<ans<<endl;
    }
    return 0;
}

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

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

    while (scanf("%d", &n)) {
      if (!n) return 0;
      int sum = 0;
      n = 1000 - n;
      for (int i = 0; i < 6; i++) {
        sum += (n / coin[i]);
        n %= coin[i];
        if (!n) break;
      }
      cout << sum << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	while(cin >> n, n) {
		n = 1000 - n;
		int r = 0;
		r += n / 500; n %= 500;
		r += n / 100; n %= 100;
		r += n / 50; n %= 50;
		r += n / 10; n %= 10;
		r += n / 5; n %= 5;
		r += n;
		cout << r << endl;
	}
	return 0;
}

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


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

return 0;
}

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

int main(void){
	int n;
	while(cin >> n){
		int currency[]={500,100,50,10,5,1};
		int count = 0;
		int pay = 1000 - n;
		if(n==0) break;
		for(int i=0;i<6;++i){
			if(pay/currency[i]>0) count+=pay/currency[i];
			pay%=currency[i];
		}
		cout << count << "\n";
	}
	return 0;
}

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

    while(true){
        int s, o, i;
        int a, b, c, d, e, f;
        
        cin >> s;
        if(s == 0){
            break;
        }
        
        o = 1000 - s;
        
        a = o / 500;
        b = (o - 500*a ) / 100;
        c = (o - 500*a - 100*b) / 50;
        d = (o - 500*a - 100*b - 50*c) / 10;
        e = (o - 500*a - 100*b - 50*c - 10* d) / 5;
        f = o - 500*a - 100*b - 50*c - 10* d - 5*e;
        
        i = a + b + c + d + e + f;
        
        cout << i << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int money;
  int change;
  while(cin >> money,money){
  money=1000-money;
  change=0;
  while(money){
    if(money>=500){
      change++;
      money-=500;
    }
    else if(money>=100){
      change++;
      money-=100;
    }
    else if(money>=50){
      change++;
      money-=50;
    }
    else if(money>=10){
      change++;
      money-=10;
    }
    else if(money>=5){
      change++;
      money-=5;
    }else{
      change++;
      money-=1;
    }
  }
  cout << change << endl;
}
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int n,cnt=0;
        cin>>n;
        if(n==0){
            return 0;
        }
        n=1000-n;
        if(n>=500){
            cnt+=n/500;
            n%=500;
        }
        if(n>=100){
            cnt+=n/100;
            n%=100;
        }
        if(n>=50){
            cnt+=n/50;
            n%=50;
        }
        if(n>=10){
            cnt+=n/10;
            n%=10;
        }
        if(n>=5){
            cnt+=n/5;
            n%=5;
        }
        if(n>=1){
            cnt+=n/1;
            n%=1;
        }
        cout<<cnt<<endl;
    }
}

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

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