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.h>
#include <queue>
#include <algorithm>

using namespace std;

//change

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

	while(cin >> n){
		if(!n) return 0;

		int ans=0;
		n = 1000 - n;

		for(int i=0 ; i<6 ; i++){
			int temp = n / coin[i];
			ans += temp;
			n -= temp*coin[i];
		}

		cout << ans << endl;


	}
	return 0;
}

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

int a,sum,ans,dx[6]={500,100,50,10,5,1};

int main (){
    cin >> a;
    a=1000-a;

    for(int i=0;i<6;i++){
    ans=a/dx[i];
    sum=sum+ans;
    a=a%dx[i];
    ans=0;
    }

    cout << sum << endl;
    return 0;
}

C++: #include <cstdio>

int main() {
	int num,n,i,a,b;
	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 <iostream>
using namespace std;
int main()
{
	int n, t, c[6] = {500, 100, 50, 10, 5, 1}, i, s, m, u;
	while (cin >> n && n)
	{
		t = 1000 - n;
		m = 0;
		while (t)
		{
			if (t >= 500)		s = 0;
			else if (t >= 100)	s = 1;
			else if (t >= 50)	s = 2;
			else if (t >= 10)	s = 3;
			else if (t >= 5)	s = 4;
			else				s = 5;
			for (i = s; i < 6; i++)
			{
				u = t / c[i];
				m += u;
				t -= c[i] * u;
			}
		}
		cout << m << endl;
	}
}

C++: #include <iostream>

int main(){
    while(true){
        int n;
        std::cin >> n;
        
        if(n == 0) {
            break;
        }
        
        n = 1000 - n;
        
        int count = 0;
        
        count += n / 500;
        n %= 500;
        count += n / 100;
        n %= 100;
        count += n / 50;
        n %= 50;
        count += n / 10;
        n %= 10;
        count += n / 5;
        n %= 5;
        count += n / 1;
        n %= 1;
    
        std::cout << count << std::endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int money,change,num=0;
        cin>>money;
        if(money==0){
            break;
        }
        change=1000-money;
        num+=(change/500);
        change%=500;
        num+=(change/100);
        change%=100;
        num+=(change/50);
        change%=50;
        num+=(change/10);
        change%=10;
        num+=(change/5);
        change%=5;
        num+=change;
        cout<<num<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_std(false);
    int n[5], count=0;

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	int j = (s - s % 500)/500;
        count += j;
	s -= j*500;
        j = (s - s % 100)/100;
        count += j;
	s -= j*100;
        j = (s - s % 100)/100;
        count += j;
	s -= j*50;
        j = (s - s % 50)/50;
        count += j;
	s -= j*10;
        j = (s - s % 10)/10;
        count += j;
	s -= j*10;
        j = (s - s % 5)/5;
        count += j;
	s -= j*5;
        count += s;

	cout << count << endl;
    }
    return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N;
	while(N){
	    N = 1000 - N;
	if (N >= 500)N -= 400;
	int ans = N / 100;
	N %= 100;
	if (N >= 50)N -= 40;
	ans += N / 10;
	N %= 10;
	if (N >= 5)N -= 4;
	ans += N;
	cout << ans << endl;
	cin>>N;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

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

int main() {
	int N;
	
	while (cin >> N, N) {
		int A = 1000 - N, ans = 0;
		
		for_(i,0,6) {
			while (A >= coin[i]) {
				A -= coin[i];
				++ans;
			}
		}
		
		cout << ans << endl;
	}
}

C++: #include <iostream>

using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int turi;
  int hara;
  int count;
  while(1){
    count=0;
    cin>>hara;
    if(hara==0) break;
    turi=1000-hara;
    while(turi!=0){
      if(turi>=500){
	turi=turi-500;
	count++;
      }
      else if(turi>=100){
	turi=turi-100;
	count++;
      }
      else if(turi>=50){
	turi=turi-50;
	count++;
      }

      else if(turi>=10){
	turi=turi-10;
	count++;
      }
      
      else if(turi>=1){
	turi=turi-1;
	count++;
      }
    }
    cout<<count<<endl;
  }
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	while (oturi > 0)
	{
		if (oturi >= 500)
		{
			count++;
			oturi -= 500;
		}
		else if (oturi >= 100)
		{
			count++;
			oturi -= 100;
		}
		else if (oturi >= 50)
		{
			count++;
			oturi -= 50;
		}
		else if (oturi >= 10)
		{
			count++;
			oturi -= 10;
		}
		else if (oturi >= 5)
		{
			count++;
			oturi -= 5;
		}
		else if (oturi >= 1)
		{
			count++;
			oturi -= 1;
		}
	}

	cout << count << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int ans = 0;
  ans += (1000 - t)/500;
  ans += ((1000 - t)/100) - 5*((1000 - t)/500);
  ans += ((1000 - t)/10)-10*((1000 - t)/100);
  cout << ans << endl;
  return 0;
}

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

int main(){
	int c[6] = {500, 100, 50, 10, 5, 1};
	int x;
	while( cin >> x , x ){
		x = 1000 - x;
		int ans = 0;
		while( x ){
			for(int i=0 ; i < 6 ; i++ ){
				if( x >= c[i] ){
					x -= c[i];
					ans++;
					break;
				}
			}
		}
		cout << ans << endl;
	}
}

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

C++: #include <stdio.h>
int main(){
int n,ans;
while(1){
scanf("%d",&n);
if(n==0)return 0;
n=1000-n;
ans=0;
while(n>=500){
n-=500;
ans++;
}
while(n>=100){
n-=100;
ans++;
}
while(n>=50){
n-=50;
ans++;
}
while(n>=10){
n-=10;
ans++;
}
while(n>=5){
n-=5;
ans++;
}
while(n>=1){
n-=1;
ans++;
}
printf("%d\n",ans);
}
}

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

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

int main(){
	int cnt = 0,i = 5;
	while(1){
		cin >> X;
		if(X==0)break;
		X = 1000-X;
		while( X > 0 ){
			while( X >= change[i] ){
				X -= change[i];
				cnt++;
			}
			i--;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
return 0;
}