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<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  while(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  while(n >= 5){
    n -=5;
    ++ans;
  }
  while(n >= 1){
    --n;
    ++ans;
  }
  cout << ans<< endl;
  return 0;
}

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

int money,c[1010],n,x;
int main(){
  while(true){
    x=0;
    scanf("%d",&money);
    if(money==0){break;}
    n=1000-money;
    for(int i=0;500<=n;i++){x++;n=n-500;}
    for(int i=0;100<=n;i++){x++;n=n-100;}
    for(int i=0;50<=n;i++){x++;n=n-50;}
    for(int i=0;10<=n;i++){x++;n=n-10;}
    for(int i=0;5<=n;i++){x++;n=n-5;}
    for(int i=0;1<=n;i++){x++;n=n-1;}
    printf("%d\n",x);
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int m;
  cin>>m;
  int co=0;
  int o=1000-m;
  if(o>500){co++;o-=500;}
  while(o>=100){co++;o-=100;}
  while(o>=50){co++;o-=50;}
  while(o>=10){co++;o-=10;}
  while(o>=5){co++;o-=5;}
  while(o>=1){co++;o--;}

  cout<<co<<endl;

}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[6], count=0, coin[] = { 500,100,50,10,5 };

    for (int i=0; i<6; i++) 
{
cin >> n[i];
if(!n[i])break;
}

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

	int s=1000 - n[i];

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int change = 1000 - n;
        int count = 0;
        if (change >= 500) {
            change -= 500;
            count++;
        } 
        if (change >= 100) {
            int coin_100 = change / 100;
            change -= 100 * coin_100;
            count += coin_100;
        } 
        if (change >= 50) {
            change -= 50;
            count++;
        }
        if (change >= 10) {
            int coin_10 = change / 10;
            change -= 10 * coin_10;
            count += coin_10;
        }
        if (change >= 5) {
            change -= 5;
            count++;
        }
        count += change;
        cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a, b[] = { 500,100,50,10,5,1 }, ruio = 0;
	cin >> a;
	a = 1000 - a;
	for (int i = 0; i < 6; i++) {
		ruio += a/b[i];
		a = a%b[i];
	}
	cout << ruio << endl;
}

C++: #include <iostream>
#define REP(i, a, n) for(int a = 0; i < n; i++)
using namespace std;


int n, d, cnt;

int main(void) {
  while(cin >> n, n != 0) {
    d = 1000 - n;

    cnt = 0;
    while(d >= 500) d -= 500, cnt++;
    while(d >= 100) d -= 100, cnt++;
    while(d >=  50) d -=  50, cnt++;
    while(d >=  10) d -=  10, cnt++;
    while(d >=   5) d -=   5, cnt++;
    while(d >=   1) d -=   1, cnt++;

    cout << cnt << endl;
  }

  return 0;
}

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

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

C++: #include <iostream>

using namespace std;

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

int main()
{
	int n;
	while (cin >> n && n)
	{
		int remaind = 1000 - n;
		int ans = 0;
		for (int i = 0; i < 6; i++)
		{
			ans += remaind / coins[i];
			remaind %= coins[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

int main() {

	int change, coins;

	cin >> change;
	change = 1000 - change;

	coins = 0;
	for (int i = 0; i < 6; ++i) {
		if (change >= coin[i]) {
			coins += change / coin[i];
			change %= change / coin[i];
			if (!change)
				break;
		}
	}
	cout << coins << endl;

	return 0;
}

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

int solve(int cost){
  int count=0;
  cost=1000-cost;
  while(cost>=500)count++,cost-=500;
  while(cost>=100)count++,cost-=100;
  while(cost>=50)count++,cost-=50;
  while(cost>=10)count++,cost-=10;
  while(cost>=5)count++,cost-=5;
  while(cost>=1)count++,cost-=1;
  return count;
}

int main(){
  int input;
  cin>>input;
  while(input){
    cout<<solve(input)<<endl;
    cin>>input;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

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