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 <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int cost;

	while(cin >> cost)
	{
		if (cost == 0) break;

		int change, changenum;
		change = 1000 - cost;
		changenum = 0;

		if (change > 500)
		{
			change -= 500;
			changenum += 1;
		}

		for (int i = 0; change >= 100; i++)
		{
			change -= 100;
			changenum += 1;
		}

		for (int i = 0; change >= 50; i++)
		{
			change -= 50;
			changenum += 1;
		}

		for (int i = 0; change >= 10; i++)
		{
			change -= 10;
			changenum += 1;
		}
		
		for (int i = 0; change >= 5; i++)
		{
			change -= 5;
			changenum += 1;
		}

		changenum += change;

		cout << changenum << endl;
	}

	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,cnt=0,cmp;
    vector<int> q;
    int w[6]={500,100,50,10,5,1};
    while(1){
        cin >> a;
        if(a==0){break;}
        q.push_back(a);
    }
    int g=q.size();
    for(int j=0;j<g;j++){
        cmp=1000-q[j];
        for(int i=0;i<6;i++){
            cnt+=cmp/w[i];
            cmp-=w[i]*(cmp/w[i]);
        }
        cout << cnt << endl;
        cnt=0;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int gold,change,count;
  while(cin>>gold){
    if(gold==0) break;
    change = 1000 - gold;
    count = 0;
    while(change!=0){
      if(change>=500){
	count++;
	change -= 500;
      }
      else if(change<500&&change>=100){
	count++;
	change -= 100;
      }
      else if(change<100&&change>=50){
	count++;
	change -= 50;
      }
      else if(change<50&&change>=10){
	count++;
	change -= 10;
      }
      else if(change<10&&change>=5){
	count++;
	change -= 5;
      }
      else if(change<5&&change>=1){
	count++;
	change -= 1;
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)

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

int main(){
	int n;
	while(cin >> n && n){
		n = 1000 - n;
		int cnt = 0;
		rep(i, 6){
			cnt += n / nums[i];
			n %= nums[i];
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){

 int num,oturi,m = 0;

while(1){
 
cin>>num;

      if(num==0){
         break;
  }else{
    
  oturi=1000-num;

   
 
    m = oturi/500;
 
    m = m+oturi%500/100;
 
    m = m+oturi%500%100/50;
  
    m = m+oturi%500%100%50/10;
 
    m = m+oturi%500%100%50%10/5;

    m = m+oturi%500%100%50%10%5/1;

    num = 0;

     
   }
  cout<<m<<'\n';
  
}

return 0;
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

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

int main(){
	int n; scanf("%d",&n);
	int m=1000-n;
	int res=0;
	for(int i=0;i<6;i++){ res+=m/c[i]; m%=c[i]; }
	printf("%d\n",res);
}

C++: #include <stdio.h>

int main(void)
{
	int money;
	int change;
	int coin;
	
	while (scanf("%d", &money) != EOF){
		coin = 0;
		if (money != 0){
			if (change / 500 != 0){
				coin += change / 500;
				change %= 500;
			}	
			if (change / 100 != 0){
				coin += change / 100;
				change %= 100;
			}
			if (change / 50 != 0){
				coin += change / 50;
				change %= 50;
			}
			if (change / 10 != 0){
				coin += change / 10;
				change %= 10;
			}
			if (change / 5 != 0){
				coin += change / 5;
				change %= 5;
			}
			if (change != 0){
				coin += change;
			}
		}
		printf("%d\n", coin);
	}
	
	return (0);
}

C++: #include <iostream>

using namespace std;

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

int main() {
  int m = 0;
  int n;
  while(cin >> m, m) {
    n = 0;
    m = 1000 - m;
    for (int i = 5; i >= 0; i--) {
      int t = m / coins[i];
      n += t;
      m -= t * coins[i];
    }
    cout << n << endl;
  }
}

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

int main(){
	
	int c[6]={500,100,50,10,5,1};
	int n;
	
	
	while(cin>>n){
		if(n!=0){
		int k=0;
		int s=0;
		n=1000-n;
	
	while(n>0){
		if(n-c[k]>=0){
			n=n-c[k];
			s++;
		}
		else
			k++;
	}
			cout<<s<<endl;
	}
	
	else
		break;
	}
	
}

C++: #include<iostream>
using namespace std;
int main(){
int n,b;while(true){cin>>b;n=1000-b;;if(n==0){break;}
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<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);
}
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(void)
{
	for (;;)
	{
		int a,b,c,d,e,f,g,h,i,j,k,l,n,m;
		d=0;
		cin>>a;
		if (a==0)
		{
			break;
		}
		b=1000-a;
		c=b/500;
		d=d+c;
		e=b%500;
		c=e/100;
		d=d+c;
		e=b%100;
		c=e/50;
		d=d+c;
		e=b%50;
		c=e/10;
		d=d+c;
		e=b%10;
		c=e/5;
		d=d+c;
		e=b%5;
		d=d+e;
		cout<<d<<endl;
	}
	return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  while(n!=0)
  {
    int now=1000;
    now-=n;
    int ans=0;
    while(now>=500)
    {
      now-=500;
      ans++;
    }
    while(now>=100)
    {
      now-=100;
      ans++;
    }
    while(now>=50)
    {
      now-=50;
      ans++;
    }
    while(now>=10)
    {
      now-=10;
      ans++;
    }
    while(now>=5)
    {
      now-=5;
      ans++;
    }
    while(now>=1)
    {
      now--;
      ans++;
    }
    cout<<ans<<endl;
    cin>>n;
  }
}