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>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n;
  while (n = in()){
    n = 1000 - n;
    int v = 0;
    for (int i = 0; i < 6; i++){
      static const int c[] = {500, 100, 50, 10, 5, 1};
      v += n / c[i];
      n %= c[i];
    }
    printf("%d\n", v);
  }

  return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> coins={500,100,50,10,5,1};
    int a;
    while(cin >> a,a){
        a=1000-a;
        int ans=0;
        rep(i,6) ans+=a/coins[i],a%=coins[i];
        cout << ans << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
int n;cin>>n;
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<endl;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int pay,remain,ans=0;

	while(1){
		cin>>pay;
		if(pay==0){
			break;
		}
		remain=1000-pay;
		ans=0;
		while(remain>=500){
			remain-=500;
			ans++;
		}
		while(remain>=100){
			remain-=100;
			ans++;
		}
		while(remain>=50){
			remain-=50;
			ans++;
		}
		while(remain>=10){
			remain-=10;
			ans++;
		}
		while(remain>=5){
			remain-=5;
			ans++;
		}
		while(remain>=1){
			remain-=1;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int solve(int n){
	n=1000-n;
	int ans=0;

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

	for(int i=0;i<6;++i) while(n>=change[i]) n-=change[i],ans++;
		
	return ans;
}

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

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	n=1000-n;
	ans+=n/500;n%=500;
	ans+=n/100;n%=100;
	ans+=n/50;n%=50;
	ans+=n/10;n%=10;
	ans+=n/5;n%=5;
	ans+=n;
	cout<<ans<<endl;
}

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

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

C++: #include<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	scanf("%d",&genkin);
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d\n",sum);

	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int m[] = {500,100,50,10,5,1};
    while(1){
    int n;
    scanf("%d",&n);
    if(n == 0)
        break;
    n = 1000 - n;
    
    int c = 0;int i = 0;
    while(n > 0){
        if(n < m[i]){
            i++;
        }else{
            n -= m[i];
            c++;
        }
    }
    printf("%d\n",c);
    }
    return 0;
}

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

int main()
{
int a,b,c;
a=0;
cin>>c;
b=1000-c;

while(b>=500){
a++;
b=b-500;
}
while(b>=100){
a++;
b=b-100;
}
while(b>=50){
a++;
b=b-50;
}
while(b>=10){
a++;
b=b-10;
}
while(b>=5){
a++;
b=b-5;
}
while(b>=1){
a++;
b=b-1;
}
cout<<a<<'\n';
return 0;
}

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

int main(){
	int change, pay, cnt;
	while(true){
		cin>>pay; if(pay==0) break;
		cnt=0;
		change = 1000 - pay;
		cnt+=  change / 500 ;
		cnt+= (change / 100) %5;
		cnt+= (change / 50)  %2;
		cnt+= (change / 10)  %5;
		cnt+= (change / 5)   %2;
		cnt+=  change 	   %5;
		cout<<cnt<<endl;
	}
	return 0;
}

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

C++: #include <iostream>

int main() {
	int a,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;




}

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

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

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

int nedan;
int oturi;
int maisuu = 0;
int i;
	

 int main(){
	cin >> oturi;
	i = 1000 - oturi;
	for(i=0 ; i<1000; )
	{
		if(nedan<500)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<100)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<50)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<10)maisuu+=1;
	}
	for(i=0 ; i<1000; )
	{
		if(nedan<5)maisuu+=1;
	}
	for(i=0 ; i<1000; ){
		if(nedan<1)maisuu+=1;
	}
	 return 0;
 }