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;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

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

int main()
{
  while(cin >> n, n){
    n = 1000 - n;

    int res = 0;
    rep(k, 6){
      res += n / coin[k];
      n -= n / coin[k] * coin[k];
    }

    cout << res << endl;
  }

  return 0;
}

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

using namespace std;

int main()
{
    int M;
    while (cin >> M, M) {        
        int res = 0;
        const int coin[] = {500, 100, 100, 50, 10, 5, 1};
        M = 1000 - M;
        for (int i = 0; i < 7; i++) {
            while (M >= coin[i]) {
                M -= coin[i];
                res++;
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(true){
		int a; cin >> a;
		if(a == 0) break;
		a = 1000 - a;

		int ans = 0;
		ans += a/500;
		a %= 500;
		ans += a/100;
		a %= 100;
		ans += a/50;
		a %= 50;
		ans += a/10;
		a %= 10;
		ans += a/5;
		a %= 5;
		ans += a;

		cout << ans << endl;
	}

	return 0;

}

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

int main()
{
  int n;
  while(cin>>n && n){
    int res = 0;
    n = 1000 - n;
    res += n / 500; n %= 500;
    res += n / 100; n %= 100;
    res += n / 50;  n %= 50;
    res += n / 10;  n %= 10;
    res += n / 5;   n %= 5;
    res += n / 1;   n %= 1;

    cout<<res<<endl;
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==1){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

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

int main()
{
while(true) {
int n;
scanf("%d", &n);
if(n == 0)
break;
int change = 1000 - n;
int ans = 0;
for(int digit = 1; digit < 1000; digit *= 10) {
int cur = change / digit % 10;
ans += (cur / 5) + (cur % 5);
}
printf("%d\n", ans);
}
return 0;
}

C++: /**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:33

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){

                int yen = 0;
                int oturi =0;
                int count = 0;

                cin >> yen;
                if(yen == 0)break;
                oturi = 1000 - yen;

                while(oturi/500 != 0){
                        oturi = oturi -500;
                        count++;        
                }
        

                while(oturi/100 != 0){
                        oturi = oturi -100;
                        count++;
                }
        

                while(oturi/50 != 0){
                        oturi = oturi -50;
                        count++;
                }
        

                while(oturi/10 != 0){
                        oturi = oturi -10;
                        count++;
                }
        

                while(oturi/5 != 0){
                        oturi = oturi -5;
                        count++;
                }
        

                count = count + oturi;        

                cout << count <<endl;

        }
    

        return 0;    


}

C++: #include <iostream>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    int money;
    while( cin >> money, money ){

    int coin_count=0;
    int rest =1000;

    rest -= money;
    int tmp =0;

    coin_count += rest /500;
    rest = rest % 500;

    coin_count += rest /100;
    rest = rest % 100;

    coin_count += rest /50;
    rest = rest % 50;

    coin_count += rest /10;
    rest = rest % 10;

    coin_count += rest /5;
    rest = rest % 5;

    coin_count += rest /1;
    cout << coin_count << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int n;
    while (cin >> n && n) {
        int cost = 1000 - n;
        int n1 = cost / 500;
        cost -= 500 * (cost / 500);
        int n2 = cost / 100;
        cost -= 100 * (cost / 100);
        int n3 = cost / 50;
        cost -= 50 * (cost / 50);
        int n4 = cost / 10;
        cost -= 10 * (cost / 10);
        int n5 = cost / 5;
        cost -= 5 * (cost / 5);
        cout << n1 + n2 + n3 + n4 + n5 + cost << '\n';
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu;
  
  cin >> money;
  oturi = 1000 - money;

  for(int i = 1000;oturi > 0;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;
  }

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

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

  while(true){
    cin >> input;
    if(input == 0) break;
    input = 1000-input;
    int n=0;
    for(int i=0;i<6;i++){
      n+=input/c[i];
      input = input%c[i];
    }
    cout << n << endl;
  }
  return 0;
}

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

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

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

int main(){
  int n;
  while(cin >> n,n){
    n = 1000-n;
    int pos = 0, ans = 0;
    while(n){
      if(n>=coin[pos]){
	n -= coin[pos];
	ans++;
      }else{
	pos++;
      }
    }
    cout << ans << endl;
  }
}