Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int money=0,money1=0,all=0;
	while(1){
	cin>>money;
	if(money==0){break;}
	money1=1000-money;
	all+=(money1/500);
	all+=(money1%500/100);
	all+=(money1%500%100/50);
	all+=(money1%500%100%50/10);
	all+=(money1%500%100%50%10/5);
	all+=(money1%500%100%50%10%5/1);
	cout<<all<<endl;
	all=0;
	}
	return 0;
}
//9:18.853クリア

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

C++: #include <bits/stdc++.h>

using namespace std;
int c[6] = {500,100,50,10,5,1};
int main(){

	int n;
	scanf("%d",&n);

	n = 1000 - n;
	int ans = 0;

	for(int i = 0;i < 6;i++){
		ans += (n / c[i]);

		n = n % c[i];
	}

	printf("%d\n",ans);

	return 0;

}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[6] = {500, 100, 50, 10, 5, 1};
int solve(int n){
	int ans = 0;
	while(1){
		for(int i = 0;i < 6;i++){
			if(n >= a[i]){
				n -= a[i];
				ans++;
				break;
			}
		}
		if(n == 0)break;
	}
	return ans;
}

int main(){
	int n;
	while(cin >> n, n){
		cout << solve(1000-n) << endl;
	}
	return 0;
}

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

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

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout<<b/500+c/100+d/50+e/10+f/5+g<<endl;
	return 0;
}

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

using namespace std;

int kane;
int oturi[6]={500,100,50,10,5,1};
int mai;

int main(){
	while(1){
		mai=0;
		cin>>kane;
		if(kane==0) break;
		for(int i=0;i<6;i++){
			mai+=kane/oturi[i];
			kane%=oturi[i];
		}
		cout<<mai<<endl;
	}
		
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
  
  while(true){
   int t;
 cin>>t;
   if(t==0){
   break;
   }
    
  
 int s=1000-t;
 int w=s/500;
 int e=(s%500)/100;
  int r=((s%500)%100)/50;
  int y=(((s%500)%100)%50)/10;
  int u=((((s%500)%100)%50)%10)/5;
  int o=(((((s%500)%100)%50)%10)%5);
  cout<< w+e+r+y+u+o <<endl;
}
}

C++: #include <iostream>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        int count = 0;
        int n = 1000-a[i];
        while (n % 500 == 0) {
            n -= 500;
            count++;
        }
        while (n % 100 == 0) {
            n -= 100;
            count++;
        }
        while (n % 50 == 0) {
            n -= 50;
            count++;
        }
        while (n % 10 == 0) {
            n -= 10;
            count++;
        }
        while (n % 5== 0) {
            n -= 5;
            count++;
        }
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

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

int main(){
  int c,t;
  int ans;
  
  while(true){
    
    scanf(" %d",&c);
    if(c==0)break;
    
    t = 1000 - c;
    
    ans = 0;
    for(int i=0;i<6;i++){
      while(t>=coin[i]){
        t-=coin[i];
        ans++;
      }
    }
    
    printf("%d\n",ans);
  }
  
  return 0;
}

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

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int price;
	while ((price = in())) {
		int change = 1000 - price, coins = 0;
		for (int c : {500, 100, 50, 10, 5, 1}) {
			coins += change / c;
			change %= c;
			if (!change)
				break;
		}
		out(coins, '\n');
	}
}