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<cmath>
#include<string>
#include<algorithm>

using namespace std;


    int main(){
        int price=0,money[6]={500,100,50,10,5,1},ret=0,cnt;
        while(1){
        cnt=0;
        cin>>price;
        ret=1000-price;
        if(price==0)break;
        for(int i=0;i<6;i++){
                while(1){
                    if(ret<money[i])break;
                    ret-=money[i];
                    cnt++;

                }
            }

        cout<<cnt<<endl;
    }
    return 0;
}

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

int main(){
	int price,count,x,n;
	int coin[] = {500,100,50,10,5,1};
	while(cin >> n && n){
		price = 1000 - n;
		count = 0;
		for(int i = 0;i<6;i++){
			x = price / coin[i];
			count += x;
			price -= coin[i] * x; 
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
int c[]={500,100,50,10,5,1};
int cn[6];

int main(){
	int a;
	cin>>a;
	while(a){
		a=1000-a;
		FOR(i,0,6){
			cn[i]=a/c[i];
			a-=cn[i]*c[i];
		}
		int ans=0;
		FOR(i,0,6)ans+=cn[i];
		cout<<ans<<endl;
		cin>>a;
	}

	
	return 0;
}

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

int coin[] = {1, 5, 10, 50, 100, 500};
int remain, in;
int main()
{
  while(cin >> in, in){
    remain = 1000 - in;
    int ans = 0;
    for(int i = 0; i < 6; i++){
      ans += remain / coin[5 - i];
      remain %= coin[5 - i];
    }
    cout << ans << 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++: //08-1 ?????????
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
using namespace std;
int main(){
    bool flg = true;
    while(flg){
        int A;
        cin >> A;
        int ans = 0;
        if(A != 0){
            A = 1000 - A;
            while(A>=500){
                A -= 500;
                ans++;
            }
            while(A>=100){
                A -= 100;
                ans++;
            }
            while(A>=50){
                A -= 50;
                ans++;
            }
            while(A>=10){
                A -= 10;
                ans++;
            }
            while(A>=5){
                A -= 5;
                ans++;
            }
            while(A>=1){
                A -= 1;
                ans++;
            }
            cout << ans << endl;
        }
        else{
            flg = false;
        }

    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	int tnok, yj;
	cin >> tnok;
	tnok = 1000 - tnok;
	if(tnok >= 500){
		yj = 1;
		tnok = tnok - 500;
	} else {
		yj = 0;
	}
	if(tnok >= 400){
		yj = yj + 4;
		tnok = tnok - 400;
	}
	else if(tnok >= 300){
		yj = yj + 3;
		tnok = tnok - 300;
	}
	else if(tnok >= 200){
		yj = yj + 2;
		tnok = tnok - 200;
	}
	else if(tnok >= 100){
		yj = yj + 1;
		tnok = tnok - 100;
	}
	if(tnok >= 50){
		yj = yj + 1;
		tnok = tnok - 50;
	}
	if(tnok >= 40){
		yj = yj + 4;
		tnok = tnok - 40;
	}
	else if(tnok >= 30){
		yj = yj + 3;
		tnok = tnok - 30;
	}
	else if(tnok >= 20){
		yj = yj + 2;
		tnok = tnok - 20;
	}
	else if(tnok >= 10){
		yj = yj + 1;
		tnok = tnok - 10;
	}
	if(tnok >= 5){
		yj = yj + 1;
		tnok = tnok - 5;
	}
	cout << tnok + yj <<endl;
 
	return 0;
}

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

	return 0;

}

C++: main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
}

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

int count(int x,int c){
    if(x>=500){
        return count(x-500,c+1);
    }
    if(x>=100){
        return count(x-100,c+1);
    }
    if(x>=50){
        return count(x-50,c+1);
    }
    if(x>=10){
        return count(x-10,c+1);
    }
    if(x>=5){
        return count(x-5,c+1);
    }
    if(x==0){
        return c;
    }
    else{
        return count(x-1,c+1);
    }
}
int main(void){
    int x;
    while(true){
        cin >> x;
        if(x==0){
            break;
        }
        cout << count(1000-x,0)<< endl;
    }
}

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

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