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 <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int M[] = {500, 100, 50, 10, 5, 1};

int main(void){
    for(int m, cnt; cin >> m, cnt = 0, m; cout << cnt << endl)
        rep(i, 6) while(m + M[i] <= 1000) m += M[i], cnt ++;
 
    return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(void)
{
	int a,b,c=0;
	cin >> a;
	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;
	
	return 0;
}

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int count=0,money=1000-n;
		while(money>=500)money-=500,count++;
		while(money>=100)money-=100,count++;
		while(money>=50)money-=50,count++;
		while(money>=10)money-=10,count++;
		while(money>=5)money-=5,count++;
		while(money>=1)money-=1,count++;
		std::cout<<count<<std::endl;
	}
	return 0;
}

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

C++: #include <iostream>
using namespace std;
main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

		n = 1000 - n;

		int ans = 0;
		int x[] = {500, 100, 50, 10, 5, 1};
		for (int i = 0; i < 6; i++)
		{
			int add = n / x[i];
			ans += add;

			n -= add * x[i];
			if (n <= 0)
			{
				break;
			}
		}

		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

void main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n",ans);
  return 0;
}

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

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

C++: #include <iostream>
#define add(coinvalue) changecoins+=(int)change/coinvalue;change%=coinvalue;
using namespace std;

int main() {
	// your code goes here
	for(;;){
		int fee;
		cin >> fee;
		if(fee==0)
			break;
		int change=1000-fee;
		int changecoins=0;
		add(500)
		add(100)
		add(50)
		add(10)
		add(5)
		add(1)
		cout << changecoins << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

double eps = 1e-10 ;

  template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  while(cin >> n){
    n = 1000-n;
    while(n >= 500){
      n -= 500;
      ++ans;
    }
    while(n >= 100){
      ++ans;
      n -= 100;
    }
    while(n >= 50){
      n -= 50;
      ++ans;
    }
    while(n >= 10){
      ++ans;
      n -= 10;
    }
    while(n >= 5){
      n -= 5;
      ++ans;
    }
    while(n >= 1){
      n -= 1;
      ++ans;
    }
    cout << ans<< endl;
  }
  return 0;
}

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

int main(void)
{
	int much;
	int c = 0;

	while(cin >> much, much > 0){
		much = 1000 - much;

		if(much >= 500){
			much %= 500;
			c++;
		}
		if(much >= 100){
			c += (int)(much / 100);
			much %= 100;
		}
		if(much >= 50){
			c += (int)(much / 50);
			much %= 50;
		}
		if(much >= 10){
			c += (int)(much / 10);
			much %= 10;
		}
		if(much >= 5){
			c += (int)(much / 5);
			much %= 5;
		}
		c += much;

		cout << c << endl;

	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <limits>
typedef long long ll;
#define REP(i,n)   for(int i=0; i<(int)(n); ++i)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); ++i)

#define in cin
#define out cout
#define pb push_back
using namespace std;

int main(){
	int n;
	while (in >> n) {
		if (!n)break;
		int a = 1000 - n,ans=0;
		int c[5] = { 500, 100, 50, 10, 5 };
		REP(i, 5) {
			ans += a / c[i];
			a %= c[i];
		}
		out << ans + a << endl;
	}
	return 0;

}

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

int C[6]={1,5,10,50,100,500};
int T[MAX+1];
void douteki();

int main(){
  int n;
 

  while(1){
    cin >> n;
    if(n == 0)break; 
    douteki();
    cout << T[1000-n] << endl;
  }



}

void douteki(){
  for(int j=0;j<=MAX;j++)T[j]=10000;
  T[0]=0;
  for(int i=0;i<6;i++){
    for(int j=C[i];j<=MAX;j++){
      T[j]=min(T[j],T[j-C[i]]+1);
    }
  }

}