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

int main(){
	int x, y;
	while(scanf("%d", &x))
		if(x == 0){
			break;
		}{
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

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

using namespace std;

#define print(a) printf("%d\n", a)

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

#define MAX(a,b) ((a)>(b)?(a):(b))


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

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

int main(){
  int num;
  int money[]={500,100,50,10,5,1};
  int i=0,ans=0;
  
  cin>>num;
  num=1000-num;
  while(num!=0){
    ans += num/money[i];
    num = num%money[i];
    i++;
  }
  printf("%d\n",ans);
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int coin[6] = {1,5,10,50,100,500};
const int sen = 1000;
int main(){
  int n;
  cin >> n;
  int oturi = sen - n;
  int sum = 0;
  int cnt = 5;
  while(oturi != 0){
    if(oturi/coin[cnt] != 0){
      sum++;
      oturi -= coin[cnt];
    }
    else{
      cnt--;
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main(){
    int N,money[6]={500,100,50,10,5,1},ans=0;
    cin>>N;
    N=1000-N;
    for(int i=0;i<6;i++){
        while(N-money[i]>=0) N-=money[i],ans++;
    }
    printf("%d\n",ans);
    return 0;
}

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);
}
if(price/100!=0){
cnt+=(price/100);
price-=(price/100);
}
if(price/50!=0){
cnt+=(price/50);
price-=(price/50);
}
if(price/10!=0){
cnt+=(price/10);
price-=(price/10);
}
if(price/5!=0){
cnt+=(price/5);
price-=(price/5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
}
return 0;
}

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

int main(){
  int n;
  int coin[] = {500, 100, 50, 10, 5, 1};

  while(cin >> n, n){
    n = 1000 - n;
    int sum = 0;
    for(int i = 0; i < 6; i++){
      sum += n / coin[i];
      n %= coin[i];
    }
    cout << sum << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m;
    
    while(true){
        cin >> m;
        if(m == 0) break;
        
        int o; //おつり
        o = 1000 - m;
        int count = 0;
        if(o >= 500){
            count = count + o / 500;
            o = o % 500;
            if(o >= 100){
                count = count + o / 100;
                o = o % 100;
            }
            if(o >= 50){
                count = count + o / 50;
                o = o % 50;
            }
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
       
        
        else if(o >= 100 && o < 500){
            
            count = count + o / 100;
            o = o % 100;
            
            if(o >= 50){
                count = count + o / 50;
                o = o % 50;
            }
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        
        else if(o >= 50 && o < 100){
            
            count = count + o / 50;
            o = o % 50;
            
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        
        else if(o >= 10 && o < 50){
            
            count = count + o / 10;
            o = o % 10;
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        else if(o >= 5 && o < 10){
            count = count + o / 5;
            o = o % 5;
            count = count + o;
            cout << count << endl;
        }
        
        else{
            count = count + o;
            cout << count << endl;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n;
	while(cin >> n && n) {
		int m = 1000 - n;

		int a[6] = {500, 100, 50, 10, 5, 1};
		int ans = 0;
		rep(i, 6) {
			if(m >= a[i]) {
				ans += m / a[i];
				m %= a[i];
			}
		}

		cout << ans << endl;
	}


	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	while(1){
	int n;
	cin>>n;
	if(n==0)break;
	int a,b,c,d,e,f,g;
	g=1000-n;
	for(a=0;a<2;a++){
		for(b=0;b<5;b++){
			for(c=0;c<2;c++){
				for(d=0;d<5;d++){
					for(e=0;e<2;e++){
						for(f=0;f<5;f++){
							if(a*500+b*100+c*50+d*10+e*5+f==g){
								cout<<a+b+c+d+e+f<<endl;
								break;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  int c[6]={500,100,50,10,5,1};
  while(cin>>n,n){
    int m=1000-n,a=0;
    for(int i=0;i<6;++i){
      a+=m/c[i];
      m-=m/c[i]*c[i];
    }
    cout<<a<<endl;
  }
  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;
}