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++: /*
	0521:Change
*/
#include	<iostream>

using namespace std;

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

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  while(cin >> t,t){
  int ans = 0;
  int t500 = (1000 - t)/500;
  int t100 = (1000 - t)/100 - 5*t500;
  int t50 =  ((1000 - t)%100)/50;
  int t10 = (((1000 - t)%100)%50)/10;
  int t5 = ((1000 - t)%10)/5;
  int t1 = ((1000 - t)%10)%5;
  ans = t500 + t100 + t50 + t10 + t5 + t1;
  cout << ans << endl;
  }
  return 0;
}

C++: //
//  main.cpp

#include <iostream>
using namespace std;


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

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

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

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int score;
int use(int money, int coin){
	int ans = money / coin;
	score += ans;
	return ans;
}

int main(){
	while (1){
		score = 0;
		int money;
		scanf("%d", &money);
		if (money == 0) return 0;
		money = 1000 - money;
		money -= use(money, 500) * 500;
		money -= use(money, 100) * 100;
		money -= use(money, 50) * 50;
		money -= use(money, 10) * 10;
		money -= use(money, 5) * 5;
		money -= use(money, 1) * 1;
		printf("%d\n", score);
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		while (b!=0)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			else if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			else if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			else if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			else if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			else if (b >= 1)
			{
				b = b - 1;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl
#define MOD  998244353

int main() {
	lint N;
	while (cin >> N, N != 0) {
		N = 1000 - N;
		lint ans = 0;
		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 / 1;
		N %= 1;
		cout << ans << enld;
	}
}

C++: #import<cstdio>
int main(){
	int i,n,c[]={0,1,5,10,50,100,500};
	for(;*c=0,scanf("%d",&n),n;printf("%d\n",*c)){
		for(n=1000-n,i=6;i;i--){
			for(;n>=c[i];){
				n-=c[i],*c++;
			}
		}
	}
}

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

int minus_five(int f, int* money)
{
  if (*money >= f)
  {
    *money -= f;
    return 1;
  }
  return 0;
}

int minus_one(int o, int* money)
{
  int result = *money / o;
  *money = *money - result*o;
  return result;
}

int main(void)
{
  int pay;
  int coin;
  while (true)
  {
    cin >> pay;
    if ( pay == 0 ) break;
    pay = 1000 - pay;
    coin = 0;

    coin += minus_five(500, &pay);
    coin += minus_one (100, &pay);
    coin += minus_five( 50, &pay);
    coin += minus_one ( 10, &pay);
    coin += minus_five(  5, &pay);
    coin += minus_one (  1, &pay);

    cout << coin << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/10;
	i=z%10;
	c=b+y+m;
	printf("%d\n",c);
	return 0;
}

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

int main(){
int total;
int change;
int count=0;
while(true){
 cin>>total;
 if(total==0){
    break;
  } 
 change=1000-total;
 while(true){
   if(change>=500){
     change-=500;
     count++;
   }else if(change>=100){
     change-=100;
     count++;
   }else if(change>=50){
     change-=50;
     count++;
   }else if(change>=10){
     change-=10;
     count++;
   }else if(change>=5){
     change-=5;
     count++;
   }else{
     change--;
     count++;
    }
 }
 cout<<count<<"\n";
 count=0;
}
return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
	int n;
	while (cin >> n && n)
	{
	cin >> 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;
}