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>
#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 = 0;
	int j = 0;

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

		cost_return = 1000 - cost_input[i];
		num = 0;

		if (cost_return < 5) {
			num = cost_return;
			break;
		}
		else {
			if (cost_return < 10) {
				num = 1 + cost_return - 5;
				break;
			}
		}


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

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

	for (int i = 0; i < j;++i) {
		CO num E
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
int a[6];
int main() {
	int L,N=0,M=0;
	while (cin >> N) {
		L = 1000 - N;
		if (N == 0) {
			break;
		}
		if (L >= 500) {
			a[0]++;
			L = L - 500;
		}
		while (L >= 100) {
			a[1]++;
			L = L - 100;
		}
		while (L >= 50) {
			a[2]++;
			L = L - 50;
		}
		while (L >= 10) {
			a[3]++;
			L = L - 10;
		}
		while (L >= 5) {
			a[4]++;
			L = L - 5;
		}
		a[5] = L;
		M = a[0] + a[1] + a[2] + a[3] + a[4] + a[5];
		cout << M << endl;
		M = 0;
		for (int i = 0; i < 6; i++) {
			a[i] = 0;
		}
	}
}

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

int main(){
	int a,b,c,d,e,f,g,h;
	int sum=0;
	while(cin>>a){
		if(a==0)break;
		b=1000-a;
		c=b/500;
		d=(b-500*c)/100;
		e=(b-500*c-100*d)/50;
		f=(b-500*c-100*d-50*e)/10;
		g=(b-500*c-100*d-50*e-10*f)/5;
		h=b-500*c-100*d-50*e-10*f-5*g;
		cout<<c+d+e+f+g+h<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
	int a[6], sum[5] = {0};
    int i = 0;
    while(a[i]) {
        std::cin >> a[i];
		i++;
        if (a[i] == 0) {
            break;
        }
  
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;
    }
   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
 }
   
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

	int yen;
	int ans=0;

	while(cin>>yen){
	if(yen==0) break;
	yen=1000-yen;
	ans=yen%5;
	yen/=5;
	ans+=yen%2;
	yen/=2;
	ans+=yen%5;
	yen/=5;
	ans+=yen%2;
	yen/=2;
	ans+=yen%5;
	ans+=yen/5;
	cout<<ans<<endl;
	}
}

C++: #include<iostream>
int main(){
	int a;
	while (std::cin >> a,a){
		int change = 1000 - a;
		int coin[] = { 500, 100, 50, 10, 5, 1 };
		int ans = 0;
		for (int i = 0; i < 6; ++i){
			while (change >= coin[i]){
				ans++;
				change -= coin[i];
			}
		}
		std::cout << ans << std::endl;
	}
	
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int mo,fite,hund,fiten,ten,go,one;
    while(1){
    cin>>mo;
    if(mo==0)break;
    mo=1000-mo;
    fite=mo/500;
    hund=mo%500/100;
    fiten=mo%500%100/50;
    ten=mo%500%100%50/10;
    go=mo%500%100%50%10/5;
    one=mo%500%100%50%10%5;
    //cout<<fite<<" "<<hund<<" "<<fiten<<" "<<ten<<" "<<go<<" "<<one<<"\n";
    cout<<fite+hund+fiten+ten+go+one<<"\n";
}
}

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

int main() {
    int Y, C[6] = {500, 100, 50, 10, 5, 1};
    while (cin >> Y) {
        if (Y == 0) break;
        int ans = 0, charge = 1000 - Y;
        for (int i = 0; i < 6; ++i) {
            int t = charge / C[i];
            charge -= t * C[i];
            ans += t;
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

int K(int a){
int p = 0;
if(a >= 500){
a = a-500;
p = p+1;
}
while(a>=100){
a = a-100;
p = p+1;
}
if(a >= 50){
a = a-50;
p = p+1;
}
while(a>=10){
a = a-10;
p = p+1;
}
if(a >= 5){
a = a-5;
p =p+1;
}
p = p+a;
return p;
}
int main() {
while(1){
int buy = 0;int maisuu = 0;
cin >> buy;
if(buy == 0){break;}
buy = 1000 - buy;
cout <<  K(buy) << endl;
}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int sum,m;
	while(1)
	{
		cin>>m;
		if(m==0)
		{
			break;
		}
		m=1000-m;
		sum=m/500+(m%500)/100+(m%500%100)/50+(m%500%100%50)/10+(m%500%100%50%10)/5+(m%500%100%50%10%5);
		cout<<sum<<endl;
	}
	return 0;
}

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

using namespace std;

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;

	cin >> in;

	change = 1000 - in;

	for (int i = 0; i < 6; i++) {
		while (change >= coin[i]) {
			change -= coin[i];
			n++;
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

C++: #include <iostream>
int main()
{
	int n;
	while(std::cin>>n,n){
		n = 1000-n;
		int 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++;
		}
		ans += n;
		printf("%d\n",ans);
	}
	return 0;
}

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	int a = 1000 - n;
	int cnt = 0;
	for(int i = 0; i < 6; ++i){
		while(a >= coin[i]){
			a -= coin[i];
			++cnt;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){

  int a;
  cin >> a;
  while(a != 0){
    
    int coin = 0;
    a = 1000-a;

    if(a>=500){
      coin++;
      a-=500;
    }
    while(a>=100){
      coin++;
      a -= 100;
    }
    if(a>=50){
      coin++;
      a-=50;
    }
    while(a>=10){
      coin++;
      a-=10;
    }
    if(a>=5){
      coin++;
      a-=5;
    }
    cout << coin+a << endl;
    cin >> a;
  }

  return (0);
}