Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

C++:  #include <functional>
 #include <algorithm>
 #include <iostream>
 #include <numeric>
 #include <iomanip>
 #include <utility>
 #include <cstdlib>
 #include <sstream>
 #include <bitset>
 #include <vector>
 #include <cstdio>
 #include <ctime>
 #include <queue>
 #include <deque>
 #include <cmath>
 #include <stack>
 #include <list>
 #include <map>
 #include <set>
 
 using namespace std;
 
 typedef vector<int> VI;
 typedef pair<int,int> pii;
 typedef long long ll;
 
 #define dump(x)  cerr << #x << " = " << (x) << endl
 #define rep(i,n) for(int i=0;i<(n);i++)
 #define ALL(a)  (a).begin(),(a).end()
 #define PB push_back
 #define sz size()
 
 const double EPS = 1e-10;
 const int INF = 100000000;
 
 int solve(int n){
 int ret=0;
 int m[]={500,100,50,10,5,1};
 rep(i,6){
 ret+=n/m[i];
 n-=m[i]*(n/m[i]);
 }
 return ret;
 }
 
 
 int main(){
 int n;
 while(cin>>n){
 if(n==0)break;
 cout<<solve(1000-n)<<endl;;
 }
 
 return 0;
 }

C++: #include<iostream>

using namespace std;

int main(){
	int input;//テ・ツ?・テ・ツ環崚ァツ板ィ
	int en[] = {500,100,50,10,5,1};//テァツ。ツャティツイツィテ」ツ?ョテァツィツョテゥツ。ツ?
	
	while(1){
		cin >> input;//テ・ツ?・テ・ツ環?
		
		if(input == 0) break;
		
		int cnt=0;
		int oturi=1000-input;
		
		for(int i=0;i<6;i++){
			cnt+=oturi/en[i];
			oturi=oturi%en[i];
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 


int main(){
	int n;
	int c[6]={500,100,50,10,5,1};
	while(cin >>n && n >0){
		n=1000-n;
		int a=0;
		rep(i,6){
			a+=n/c[i];
			n%=c[i];
		}
		cout<<a<<endl;
	}
}

C++: #include <stdio.h>

int main(void) {
	int n, i,cou, list[6] = {500, 100, 50, 10, 5, 1};
	
	while(scanf("%d", &n)){
		if(n == 0) break;
		cou = 0;
	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 C[6] = {500, 100, 50, 10, 5, 1};	// 0:500円 1:100円 2:50円 3:10円 4:5円 5:1円
	int price;
	int change = 1000;
	int coin = 0;
	
	for(;;){
		change = 1000;
		coin = 0;
		cin >> price;
		if(price == 0)	break;
		change -= price;
	
		for(int i = 0; i < 6; i++){
			coin += change / C[i];
			change %= C[i];
		}
	
		cout << coin;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int count(int x, int c){
   if(x >= 500){
       return count(x-500, c+1);
   }
   if(x >= 100){
       return count(x-100, c+1);
   }
   if(x >= 50){
       return count(x-50, c+1);
   }
   if(x >= 10){
       return count(x-10, c+1);
   }
   if(x >= 5){
       return count(x-5, c+1);
   }
   if(x == 0){
       return c;
   }
   else {
       return count(x-1,c+1);
   }
}

int main (void){
   int x;
   while (true){
       cin >> x;
       if(x == 0) {
           break;
       }
       cout << count(1000 - x, 0) << endl;
   }
}

C++: #include<stdio.h>
int main(void) {
	int cost, coin, cv[] = { 500,100,50,10,5,1 };
	while (scanf("%d", &cost))
	{
		if (cost == 0)break;
		coin = 0;
		cost = 1000 - cost;
		for (int i = 0; i < 6; i++)
		{
			coin += cost / cv[i];
			cost = cost % cv[i];
		}
		printf("%d\n", coin);
	}
	return 0;
}

C++: #include <stdio.h>
using namespace std;

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
}

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

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

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

C++: #include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		n = 1000 - n;
		int count = 0;
		count += n / 500;
		n %= 500;
		count += n / 100;
		n %= 100;
		count += n / 50;
		n %= 50;
		count += n / 10;
		n %= 10;
		count += n / 5;
		n %= 5;
		count += n;
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

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

int i, ans;



int main() {


	while (true) {
		cin >> i;
		if (i == 0) break;
		i = 1000 - i;
		ans += i / 500;
		i %= 500;
		ans += i / 100;
		i %= 100;
		ans += i / 50;
		i %= 50;
		ans += i / 10;
		i %= 10;
		ans += i / 5;
		i %= 5;
		ans += i;
		cout << ans << endl;
		ans = 0;
	}


	return 0;
}