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<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,asum=0,bsum=0;
	for(int i=0;i<4;i++)
	{
		cin>>a;
		asum+=a;
	}
	for(int i=0;i<4;i++)
	{
		cin>>b;
		bsum+=b;
	}
	if(asum>=bsum)
		cout<<asum<<endl;
	else
		cout<<bsum<<endl;
	return 0;
}

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

int main()
{
	int pay;
	int change;
	int coin;
	while (cin >> pay)
	{
		if(pay == 0) break;
		coin = 0;
		change = 1000 - pay;
		while (change >= 500)
		{
			coin++;
			change -= 500;
		}
		while (change >= 100)
		{
			coin++;
			change -= 100;
		}
		while (change >= 50)
		{
			coin++;
			change -= 50;
		}
		while (change >= 10)
		{
			coin++;
			change -= 10;
		}
		while (change >= 5)
		{
			coin++;
			change -= 5;
		}
		while (change >= 1)
		{
			coin++;
			change -= 1;
		}
		cout << coin << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	cin >> a;
	if (a > 0)
	{
		c = 0;
		a = 1000 - a;
		b = a;
		b = a / 500;
		c = c + b;
		a = a % 500;
		b = a / 100;
		c = c + b;
		a = a % 100;
		b = a / 50;
		c = c + b;
		a = a % 50;
		b = a / 10;
		c = c + b;
		a = a % 10;
		b = a / 5;
		c = c + b;
		a = a % 5;
		b = a;
		c = c + b;
		cout << c << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int mian(void){
	int n,k;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		k += n /500;  n %=500;
		k += n/100;   n %=100;
		k += n/50;    n %= 50;
		k += n/10;    n %= 10;
		k += n/5;     k += n%5;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)

using namespace std;

int main(void) {	
	int n;
	while (cin >> n && n > 0) {
		int ans = 0;
		n = 1000 - n;
		ans += n / 500;
		n %= 500;
		ans += n / 100;
		n %= 100;
		ans += n / 50;
		n %= 50;
		ans += n / 10;
		n %= 10;
		ans += n / 5;
		n %= 5;
		ans += n;
		
		cout << ans << endl;
		
	}
				  
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	if(n>=500){
		m = n/500;
		n = n%500;
	}
	if(n>=100){
		m = m+n/100;
		n = n%100;
	}
	if(n>=50){
		m = m+n/50;
		n = n%50;
	}
	if(n>=10){
		m = m+n/10;
		n = n%10;
	}
	if(n>=5){
		m = m+n/5;
		n = n%5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

        return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

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

C++: #include<stdio.h>
int main()
{
	int cnt=0, a, b, i, j;
	scanf("%d", &a);
	while (1) {
		if (a >= 500) {
			a = a - 500;
			cnt++;
		}
		else if (a >= 100) {
			a = a - 100;
			cnt++;
		}
		else if (a >= 50) {
			a = a - 50;
			cnt++;
		}
		else if (a >= 10) {
			a = a - 10;
			cnt++;
		}
		else if (a >= 1) {
			a = a - 1;
		}
		if (a == 0) {
			break;
		}
	}
	printf("%d\n", cnt);
}

C++: #include<cstdio>
using namespace std;
int money[6]{500,100,50,10,5,1};
void solve(int price){
  int ans{0};
  for(int i{0} ; i< 6 ; i++){
    while(price >= money[i]){
      price -= money[i];
      ans++;
    }
  }
  printf("%d\n",ans);
}
int main(){
  int price;
  while(true){
    scanf("%d",&price);
    if(price == 0)
      break;
    solve(1000 - price);
  }
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt;
cin>>price;
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=(price%500);
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
return 0;
}

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

int change[6]={1,10,50,100,500};
int cnt[6];
int n;

int main(){
cin >> n;
n = 1000-n;
for( int i = 5; i >= 0; i-- ){
while(n>=change[i]){
n-=change[i];
cnt[i]++;
}
}
int ans=0;
for(int i = 0; i < 6; i++ )
ans += cnt[i];
cout << ans << endl;
return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        
        if (a[i] == 0) break;
        
        int count = 0;
        int n = 1000-a[i];
        while (n % 500 == 0) {
            n -= 500;
            count++;
        }
        while (n % 100 == 0) {
            n -= 100;
            count++;
        }
        while (n % 50 == 0) {
            n -= 50;
            count++;
        }
        while (n % 10 == 0) {
            n -= 10;
            count++;
        }
        while (n % 5== 0) {
            n -= 5;
            count++;
        }
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

int main(){
	for(int i=0; i<5; i++){

		int C;
		
		cin >> C ;


		cout << (1000-C)/500 + (1000-C)/100-5*((1000-C)/500) + 
				(1000-C)/50-2*((1000-C)/100) + (1000-C)/10-5*((1000-C)/50) +
				(1000-C)/5-2*((1000-C)/10) + (1000-C)-5*((1000-C)/5) << endl;
	}



}

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

int main() {
	int n,a,i=0;
	cin>>n;
	a=1000-n;
	if(a>=500){
		i+=1;
		a-=500;
	}
	if(a>=100){
		int b=a/100;
		i+=b;
		a-=100*b;
	}
	if(a>=50){
		i+=1;
		a-=50;
	}
	if(a>=10){
		int b=a/10;
		i+=b;
		a-=10*b;
	}
	if(a>=5){
		i+=1;
		a-=5;
	}
	if(a>=1)
		i+=a;
	cout<<i;
	return 0;
}

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

int main() {
	int data, ans;
	while (1) {
		cin >> data; if (data == 0) break;
		ans = 0; data = 1000 - data;
		while (data >= 500) { data = data - 500; ans++; }
		while (data >= 100) { data = data - 100; ans++; }
		while (data >=  50) { data = data -  50; ans++; }
		while (data >=  10) { data = data -  10; ans++; }
		while (data >=   5) { data = data -   5; ans++; }
		while (data >=   1) { data = data -   1; ans++; }
		cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		n=1000-n;
		int res=0;
		res+=n/500;
		n-=n/500*500;
		res+=n/100;
		n-=n/100*100;
		res+=n/50;
		n-=n/50*50;
		res+=n/10;
		n-=n/10*10;
		res+=n/5;
		n-=n/5*5;
		res+=n;
		cout<<res<<endl;
	}
	return 0;
}