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>
using namespace std;

int main() {
	int a,b=0;
	while(1){
		cin >> a;
		if(a==0) break;
		a=1000-a;
		if(a>500){
			a-=500;
			b++;
		}
	
		while(1){
			if(a<100) break;
			a-=100;
			b++;
		}

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

C++: #include <iostream>

int main(void){
  int price;

  while(1){
    int cnt = 0;
    std::cin >> price;
    if(price == 0)  return 0;
    price = 1000 - price;
    while(1){
      if(price >= 500){
        cnt++; price -= 500;
      }else if(price >= 100){
        cnt++; price -= 100;
      }else if(price >= 50){
        cnt++;  price -= 50;
      }else if(price >= 10){
        cnt++; price -=10;
      }else if(price >= 5){
        cnt++; price -= 5;
      }else{
        cnt += price;
        break;
      }
    }
    std::cout << cnt << std::endl;
  }
}

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

C++: #include <stdio.h>

int main(void)
{
	int in;
	int out[1000] = {0};

	int rem = 0;
	int rnd = 0;


	while(1)
	{
		scanf("%d",&in);

		if(in == 0)
			break;

		rem = 1000 - in;

		while(rem)
		{
			if(rem >= 500){
				rem -= 500;
				out[rnd]++;
				}else

			if(rem >= 100){
				rem -= 100;
				out[rnd]++;
				}else

			if(rem >= 50){
				rem -= 50;
				out[rnd]++;
				}else

			if(rem >= 10){
				rem -= 10;
				out[rnd]++;
				}else

			if(rem >= 5){
				rem -=5;
				out[rnd]++;
				}else

			if(rem >= 1){
				rem -= 1;
				out[rnd]++;
				}
		}

		rnd++;

	}



	for( in = 0 ; in < rnd ; in++){
		printf("%d\n",out[in]);}

	return 0;
}

C++: #include <iostream>

using namespace std;

int n,a,b,c,d,e,f;

int main(void){

  while( cin >> n , n ){

    n = 1000 - n;
    a = b = c = d = e = f = 0;

    while( n >= 500 ){
      a++;
      n -= 500;
    }
    while( n >= 100 ){
      b++;
      n -= 100;
    }
    while( n >= 50 ){
      c++;
      n -= 50;
    }
    while( n >= 10 ){
      d++;
      n -= 10;
    }
    while( n >= 5 ){
      e++;
      n -= 5;
    }
    while(n){
      f++;
      n--;
    }
    cout << a + b + c + d + e + f << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

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

	
	return 0;
	
}

C++: #include <iostream>
using namespace std;
int main(){
  int n ,coin=0;

  while ( 1 ){
    cin >> n;
    if( n == 0 ){
      break;
    }
 
    n = 1000 - n; 
    
    if( n >= 500 ){
      while( n >= 500 ){
	n -= 500;
	coin++;
      }
    }
    
    if( n >= 100 ){
      while( n >= 100 ){
	n -= 100;
	coin++;
      }
    }
  
    if( n >= 50 ){
      while( n >= 50 ){
	n -= 50;
	coin++;
      }
    }
    
    if( n >= 10 ){
      while( n >= 10 ){
	n -= 10;
	coin++;
      }
    }
    
    if( n >= 5 ){
      while( n >= 5 ){
	n -= 5;
	coin++;
      }
    }
    
    if( n >= 1 ){
      while( n >= 1 ){
	n -= 1;
	coin++;
      }
    }
    
    cout << coin << endl;
    coin = 0;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){
  int t,a,ans,cnt;
  while(1){
    ans=0,cnt=0;
    cin >> t;
    if(t==0){
      break;
    }
    a=1000-t;
    if(500<=a){
      cnt=a/500;
      ans=a/500;
      a=a-(cnt*500);
    }


    if(100<=a){
      cnt=a/100;
      ans+=a/100;
      a=a-(cnt*100);
    }

    if(50<=a){
      cnt=a/50;
      ans+=a/50;
      a=a-(cnt*50);
    }

    if(10<=a){
      cnt=a/10;
      ans+=a/10;
      a=a-(cnt*10);
    }

    if(5<=a){
      cnt=a/5;
      ans++;
      a=a-5;
    }

    cout << ans+a << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main() {

	int n;

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

		cout << t << endl;
	}

	return 0;

}

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

int main(){
	int money=1000,m;
	for(int m;cin>>m;money=1000){
		if(m==0)break;
		money-=m;
		int count;
		for(count=0;money;){
			//cout<<"money:"<<money<<endl;
			if(money/500){
				money-=500;
			}
			else if(money/100){
				money-=100;
			}
			else if(money/50){
				money-=50;
			}
			else if(money/10){
				money-=10;
			}
			else if(money/5){
				money-=5;
			}
			else if(money/1){
				money-=1;
			}
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: /*
	0521:Change
*/
#include	<iostream>

using namespace std;

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

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  while(cin >> t,t){
  int ans = 0;
  int t500 = (1000 - t)/500;
  int t100 = (1000 - t)/100 - 5*t500;
  int t50 =  ((1000 - t)%100)/50;
  int t10 = (((1000 - t)%100)%50)/10;
  int t5 = ((1000 - t)%10)/5;
  int t1 = ((1000 - t)%10)%5;
  ans = t500 + t100 + t50 + t10 + t5 + t1;
  cout << ans << endl;
  }
  return 0;
}

C++: //
//  main.cpp

#include <iostream>
using namespace std;


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