Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum;
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum << endl;
	
	return 0;
}

C++: //
//  main.cpp
//  hoge
//
//  Created by ???????????? on 2017/11/09.
//  Copyright ?? 2017??´ ????????????. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int d[5];
    for (int i=0; i<5; i++) {
        cin >> d[i];
    }
    
    for (int i=0; i<5; i++) {
        int n=1000-d[i],count=0;
        
        if(d[i] == 0) break;
        
        while (n % 5 == 0) {
            if(n % 500 == 0) {
                count++;
                n-=500;
                continue;
            }
            if(n % 100 == 0) {
                count++;
                n-=100;
                continue;
            }
            if(n % 50 == 0) {
                count++;
                n-=50;
                continue;
            }
            if(n % 10 == 0) {
                count++;
                n-=10;
                continue;
            }
            if(n % 5 == 0) {
                count++;
                n-=5;
                continue;
            }
        }
        count+=n;
        cout << n << endl;
    }
    
    return 0;
}

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;
}