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>
using namespace std;
int main()
{
	while(1)
	{
		int n; cin >> n ;
		if(!n) break;
		int money=1000-n; int cnt=0;
		while(money>=500) {cnt++,money-=500;}
		while(money>=100) {cnt++,money-=100;}
		while(money>=50) {cnt++,money-=50;}
		while(money>=10) {cnt++,money-=10;}
		while(money>=5) {cnt++,money-=5;}
		while(money>=1) {cnt++,money-=1;}
		cout << cnt << endl;
	}
}

C++: #include <iostream>

using namespace std;

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

int main()
{
	int n;
	while (cin >> n && 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;
}

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

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

int main() {

	int change, coins;

	cin >> change;
	change = 1000 - change;

	coins = 0;
	for (int i = 0; i < 6; ++i) {
		if (change >= coin[i]) {
			coins += change / coin[i];
			change %= change / coin[i];
			if (!change)
				break;
		}
	}
	cout << coins << endl;

	return 0;
}

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

int solve(int cost){
  int count=0;
  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;
  return count;
}

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

C++: #include<iostream>

using namespace std;

int main(void){
	
	int coin[6]={500,100,50,10,5,1},price,sum;
	while(cin>>price,price){
		sum=0;
		price=1000-price;
		for(int i=0;i<6;i++){
			while(price>=coin[i]){
				price=price-coin[i];
				sum++;
			}
		}
		cout<<sum<<endl;
	}
}

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

int main() {
  for (int i = 0; i < 5; i++) {
    int n; cin >> n;
    
    if (n == 0) break;
    int ch = 1000 - n;
    
    int ans = 0;
    if (ch > 0 && ch >= 500) {
      ans += ch / 500;
      ch %= 500;
    }
    if (ch > 0 && ch >= 100) {
      ans += ch / 100;
      ch %= 100;
    }
    if (ch > 0 && ch >= 50) {
      ans += ch / 50;
      ch %= 50;
    }
    if (ch > 0 && ch >= 10) {
      ans += ch / 10;
      ch %= 10;
    }
    if (ch > 0 && ch >= 5) {
      ans += ch / 5;
      ch %= 5;
    }
    if (ch > 0 && ch >= 1) {
      ans += ch / 1;
    }
    
    cout << ans << endl;
  }
}

C++: #include <cstdio>

int main() {
	int num,n,i,a,b;
	a=0,b=0,i=0;
	scanf("%d",&num);
	n=1000-num;

	if (n>500) {
		i++;
		n=(n-500);
	}
	if (n>100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>50){
		i++;
		n=(n-50);
	}
	if (n>10){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>5){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	return 0;
}

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

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

int main() {
  while (true) {
    int p;
    cin >> p;
    if (!p)
      break;
    int ans{};
    p = 1000 - p;
    for (int i{}; i < 6; ++i) {
      ans += p / coins[i];
      p %= coins[i];
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

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

int main(){

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

	cin >> pay;
	money = 1000 - pay;
	change = 0;
	
	rep(i, 6){
		change += money / c[i];	
		money = money % c[i];
	}

	cout << change << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    while(1) {
        int n;
        cin>>n;
        if(n==0) break;
        n=1000-n;
        vector<int> a={500,100,50,10,5,1};
        int ans=0;
        FORE(x,a) {
            ans+=n/x;
            n%=x;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  int M;
  cin >> M;
  int m = 1000 - M;

  int ans = 0;
  while (m > 0) {
    if (m >= 500) {
      m -= 500;
    } else if (m >= 100) {
      m -= 100;
    } else if (m >= 50) {
      m -= 50;
    } else if (m >= 10) {
      m -= 10;
    } else if (m >= 5) {
      m -= 5;
    } else {
      m--;
    }

    ans++;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

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

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

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

  while (cin >> n){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include<stdio.h>

int mian(void){
	int n,k;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		k += n /500;  n %=500;
		k += n/100;   n %=100;
		k += n/50;    n %= 50;
		k += n/10;    n %= 10;
		k += n/5;     k += n%5;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  
  cin >> money;
  oturi = 1000 - money;
  for(int i = 1000;oturi > 10;i /= 10){
    oturi %= i;
    if(oturi >= i/10){
      (oturi / (i/10) >= 5) ? (maisu += oturi / (i/10) - 4) : (maisu += oturi / (i/10));
    }
  }
  cout << maisu << endl;
    
    return 0;
  }