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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
int coins[] = { 500, 100, 50, 10, 5, 1 };

int main()
{
//	cut here before submit 
//	freopen ("testcase.change2", "r", stdin );
	string str = "";

	while (getline (cin, str ) ){
		int money;
		stringstream ss(str);
		ss >> money;
		
		if (money == 0 ){
			break;
		} // end if
		int change = 1000 - money;
		int res = 0;
		int i;

		for (i = 0; i < sizeof(coins)/sizeof(coins[0]); ++i) {
			while (change >= coins[i] ){
				change -= coins[i];
				++res;
			} // end while
		} // end for

		cout << res << endl;		
		
	} // end loop
		
	return 0;
}

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

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num_answer = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

	}
	

	for (int i = 0; i < j;++i) {
		cost_return = 1000 - cost_input[i];
		num_answer = 0;

		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1)
		{
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}

		CO num_answer E
	}
}

C++: #include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,j,z;
	scanf("%d",&z);
	while(z!=0){
	a=1000-z;
	if(a>=500){
		s=a/500;
		a=a%500;
	}
	if(a>=100){
		d=a/100;
		a=a%100;
	}
	if(a>=50){
		f=a/100;
		a=a%50;
	}
	if(a>=10){
		g=a/10;
		a=a%10;
	}
	if(a>=5){
		h=a/5;
		a=a%5;
	}
	if(a>=1){
		j=a/1;
		j=j+1;
	}
	printf("%d\n",s+d+f+g+h+j);
	scanf("%d",&z);
	}
	return 0;
}

C++: #include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		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;

int main() {
	int N;
	cin >> N;
	vector<int>A;
	A.push_back(500);
	A.push_back(100);
	A.push_back(50);
	A.push_back(10);
	A.push_back(5);
	A.push_back(1);
	while (N != 0) {
		int ans = 0;
		int num = 1000 - N;
		for (int i = 0; i < 6; i++) {
			while (num >= A.at(i)) {
				ans++;
				num -= A.at(i);
			}
		}
		cout << ans << endl;
		cin >> N;
	}
}

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

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

C++: #include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

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

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

}

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

C++: // https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0521?year=2008

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;

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

        int a = n / 500;
        n %= 500;

        int b = n / 100;
        n %= 100;

        int c = n / 50;
        n %= 50;

        int d = n / 10;
        n %= 10;

        int e = n / 5;
        int f = n % 5;

        int ans = a + b + c + d + e + f;
        cout << ans << endl;
    }
    return 0;
}

/*
 * 
 */