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 <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  while (1) {
    int in;
    cin >> in;
    if (in == 0) break;
    int n = 1000 - in;

    int c = 0;
    c += n / 500;
    n %= 500;

    c += n / 100;
    n %= 100;

    c += n / 50;
    n %= 50;

    c += n / 10;
    n %= 10;

    c += n / 5;
    n %= 5;

    c += n / 1;
    n %= 1;

    println(str(c));
  }
  return 0;
}

C++: #include <stdio.h>
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  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;
  printf("%d\n",ans+n%5);
  
}

C++: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> bills = {500, 100, 50, 10, 5, 1};
    int n;
    while(cin >> n and n) {
        int change = 1000 - n;
        int ans = 0;
        for(int bill : bills) {
            while(change >= bill) {
                change -= bill;
                ans++;
            }
        }
        cout << ans << endl;
    }
    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 <= 5; i++) {
			ans = ans + n / w[i];
			n = n - n / w[i] * w[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main() {
	int coin[6]={500,100,50,10,5,1},price,sum;
	while (true)
	{
	    scanf("%d",&price);
		if (price == 0) break;
		sum =0;
		price = 1000-price;
		for (int i = 0; i <= 5; i++)
		{
				while (price>=coin[i]) {
					price-=coin[i];
					sum++;
				}



		}
		printf("%d\n", sum);
	}




	
	return 0;
}

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

	int m, count;

	cin >> m;

	while (m != 0){
		count = 0;
		m = 1000 - m;
		if (m >= 500){
			count += m / 500;
			m /= 500;
		}
		if (m >=100){
			count += m / 100;
			m /= 100;
		}if (m >= 50){
			count += m / 50;
			m /= 500;
		}if (m >= 10){
			count += m / 10;
			m /= 50;
		}if (m >= 5){
			count += m / 5;
			m /= 5;
		}
		count += m;

		cout << count << endl;

		cin >> m;
	}

}

C++: 






 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe

































































 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe




















 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe








































#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

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

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "\n";
 
    
    }
    return 0;

}