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 <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define P pair<int, int>
int main (){ 
     int a = 1;
    
    while(a != 0){
        cin >> a ;
       if(a == 0){
           break;
       }
        a = 1000 - a ;
        int num = 0 ;
        num += a / 500 ;
        a -= 500 * (a / 500) ;
        num += a / 100 ;
        a -= 100 * (a / 100) ;
        num += a / 50 ;
        a -= 50 * (a / 50) ;
        num += a / 10 ;
        a -= 10 * (a / 10) ;
        num += a / 5 ;
        a -= 5 * (a / 5) ;
        num += a ; 
        cout << num << endl;
        a = 1 ;
    }
    

}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int a,b,c=0;
	cin >> a;
	while(a!=0){
	b=1000-a;
	c+=b/500;
	b=b%500;
	c+=b/100;
	b=b%100;
	c+=b/50;
	b=b%50;
	c+=b/10;
	b=b%10;
	c+=b/5;
	c+=b%5;
	cout << c << endl;
	c=0;
	cin >> a;
	}
	
	return 0;
}

C++: #include <cstdio>

int main (int argc, char const* argv[])
{
	
	int coin[6]={500,100,50,10,5,1};
	
	int a,r=0,m;
	
	while(true){
	
	scanf("%d",&m);
	if(m==0) break;
	m=1000-m;
	r=0;
	for(int i=0;i<6;i++){
		a=m/coin[i];
		r+=a;
		m-=(a*coin[i]);
	}
	
	
	printf("%d\n",r);
	
	}
	return 0;
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

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

int main(){
    int mon,man;
    while(1){
        cin >> mon;
        if(mon == 0){
            break;
        }
        mon = 1000 - mon;
        man = 0;
        if(mon >= 500){
            man += mon / 500;
            mon = mon % 500;
        }
        if(mon >= 100){
            man += mon / 100;
            mon = mon % 100;
        }
        if(mon >= 50){
            man += mon / 50;
            mon = mon % 50;
        }
        if(mon >= 10){
            man += mon / 10;
            mon = mon % 10;
        }
        if(mon >= 5){
            man += mon / 5;
            mon = mon % 5;
        }
        man += mon;
        cout << man << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	
	while (1)
	{int a=1;
	int b;
	int c=0;
	int cz=0;

		cin >> a;
		if (a == 0)
		{
			break;
		}
		b = 1000-a;

		if (b >= 500)
		{
			cz = b / 500;
			c = c +cz ;
			b = b % 500;
		}
		 if (b >= 100)
		{
			cz = b /100;
			c = c + cz;
			b = b % 100;
			
		}
		 if (b >= 50)
		{
			cz = b / 50;
			c = c + cz;
			b = b % 50;
		 }
		 if (b >= 10)
		{
			cz = b / 10;
			c = c + cz;
			b = b % 10;
		}
		 if (b >= 5)
		{
			cz = b / 5;
			c = c + cz;
			b = b % 5;
		 }
		 if (b >= 1)
		{
			cz = b /1;
			c = c + cz;
			b = b % 1;
		}

		cout << c << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int N = 1001;
const int C = 6;
const int INF = 1e9;

int main() {
  int dp[N];
  REP(i, N) dp[i] = INF;
  dp[0] = 0;
  int cs[C] = {1, 5, 10, 50, 100, 500};
  REP(i, C) FOR(j, cs[i], N) dp[j] = min(dp[j], dp[j - cs[i]] + 1);
  int N;
  while(cin >>N && N) cout <<dp[1000 - N] <<endl;
  return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    int m;
    cin >> m;
    if (!m) return 0;
    m = 1000 - m;
    int r = 0, c[6] = { 500, 100, 50, 10, 5, 1 };
    for (int i = 0; i < 6; i++) {
      r += m / c[i];
      m %= c[i];
    }
    cout << r << endl;
  }
}

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;
}
cout<<cnt<<endl;
}
return 0;
}

C++: #include<stdio.h>

int main(void){
  int money;
  int n;
  int i;

  n = 0;

  scanf("%d", &money);

  money = 1000 - money;

  if (money >= 500){
    n += money / 500;
    money %= 500;
  }
  if (money >= 100 && money < 500){
    n += money / 100;
    money %= 100;
  }
  if (money >= 50 && money < 100){
    n += money / 50;
    money %= 50; 
  }
  if (money >= 10 && money < 50){
    n += money / 10;
    money %= 10;
  }
  if (money >= 5 && money < 10){
    n += money / 5;
    money %= 5;
  }
  

  n += money;

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

  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(a!=0){b=1000-a;
c=0;
if(b>=500){b=b-500; c=c+1;}
if(b>=100){while(b>=100){b=b-100; c=c+1;}}
if(b>=50){b=b-50; c=c+1;}
if(b>=10){while(b>=10){b=b-10; c=c+1;}}
if(b>=5){b=b-5; c=c+1;}
c=b+c;
cout << c<<endl;
}
}
}

C++: #include <cstdio>
using namespace std;
int main()
{while(1){
 int a;
 scanf("%d",&a);
if(a==0) return 0;
 a=1000-a;
 printf("%d\n",a/500a+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5;}
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   return 0;
}