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 <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-10;
const vi emp;

int n;

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

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

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;



	while (true) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

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

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

int main(){
	int n;
	while(cin >> n, n){
		int ans = 0;
		n = 1000 - n;

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

C++: #include <iostream>
using namespace std;
int main(void){
    int m,a500,a100,a50,a10,a5,a1,k,sum=0;
    //cin >> m;
    
    while(true){
        cin >> m;
        if(m==0){
            break;
        }
        for(int i=0;i<5;i++){
            k=1000-m;
            a500=k/500;
            k=k%500;
            a100=k/100;
            k=k%100;
            a50=k/50;
            k=k%50;
            a10=k/10;
            k=k%10;
            a5=k/5;
            k=k%5;
            a1=k;
            sum=a500+a100+a50+a10+a5+a1;
        }
    
    cout << sum << endl;
    }
}

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

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

int main(){
  int i,j,n,ss,count=0,c[6]={1,5,10,50,100,500};

  while(cin >> n){
    j=0;
    count=0;
    ss=1000-n;
    for(i=5;i>=0;i--){
      if(ss>=c[i]){
	j+=ss/c[i];
	ss=ss%c[i];
      } 
    }
    cout << j << endl;
    
  }





}

C++: #include <stdio.h>

int main(void) {
	int n, i,cou = 0, list[6] = {500, 100, 50, 10, 5, 1};
	
	scanf("%d", &n);
	n = 1000 - n;
	for( i = 0; 6 > i; i++){
		cou += n/list[i];
		n %= list[i];
		
		if(n == 0) break;
	}
	printf("%d\n", cou);
	return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans<<endl;

}

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int C[6] = {500, 100, 50, 10, 5, 1};
int main(void){
	int n;
	cin >> n;
	n = 1000-n;
	int cnt = 0;
	int val = 0;
	while(n != 0){
		if(n - C[val] < 0){
			val++;
		}else{
			n -= C[val];
			cnt++;
		}
	}
	FIN(cnt);

	return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
 int n;
 cin >> n;
 int remaind = 1000 - n;
 int ans = 0;
 for (int i = 0; i < 6; i++)
 {
  ans += remaind / coins[i];
  remaind %= coins[i];
 }
 cout << ans << endl;
 return 0;
}

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

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		n = 1000 - n;
		int ans = 0, i;
		int w[6] = { 500,100,50,10,5,1 };
		for (i = 0; i <= 6; i++) {
			ans = ans + n / w[i];
			n = n - n / w[i] * w[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

#define PI 4*atan(1);

int main(){
  int y, b = 1000, c = 0;
  cin >> y;
  b -= y;
  for(int i = 0;; i++){
    if(b - 500 >= 0){
      b -= 500;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 100 >= 0){
      b -= 100;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 50 >= 0){
      b -= 50;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 10 >= 0){
      b -= 10;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 5 >= 0){
      b -= 5;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 1 >= 0){
      b -= 1;
      c++;
      if(b == 0){
        break;
      }
    }
  }
  cout << c << endl;
}