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 <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>

#define _USE_MATH_DEFINES
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define atcoder 1000000007
#define MAX_N 100

using namespace std;

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

int main() {

	int n,ans = 0;

	while (cin >> n, n) {
		n = 1000 - n;
		REP(i, 6) {
			int m = n / V[i];
			n -= V[i] * m;
			ans += m;
		}
		cout << ans << endl;
		ans = 0;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int a,b;
  int count;
  while(1){
    count = 0;
    cin >> a;
    if( a == 0) break;

    b = 1000 - a;
    a = b%500;
    count = count + b/500;

    b= a%100;
    count = count + a/100;

    a = b%50;
    count = count + b/50;

    b = a%10;
    count = count + a/10;

    a = b%5;
    count = count + b/5;

    b = a%1;
    count = count + a/1;

    cout << count <<endl;

  }
  return 0;
}

C++: //============================================================================
// Name        : oturi.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int pay = 1000,buy,oturi = 0,gohyaku,gohyakua,hyaku,hyakua,goju,gojua,ju,jua,go,goa;
    while(1){
	cin >> buy;
	if(buy == 0){
		break;
	}
	oturi = pay - buy;
	gohyakua = oturi % 500;
	gohyaku = oturi / 500;
	hyakua = gohyakua % 100;
	hyaku = gohyakua / 100;
	gojua = hyakua % 50;
	goju = hyakua / 50;
	jua = gojua % 10;
	ju = gojua / 10;
	goa = jua % 5;
	go = jua / 5;
	cout << gohyaku + hyaku + goju + ju + go + goa << endl;
    }
	return 0;
}

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

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  int c[] = {500,100,50,10,5,1};
  cin >> n;

  n = 1000-n;
  // 996  = 500 + 4*100 + 1 * 50 + 4*10 + 1*5 + 1
  int ans =0;
  for( int i=0;i<6;i++ ){
    if( n >= c[i] ){
      ans += n / c[i];
      n = n% c[i];
    }
  }
  cout << ans << endl;
}

C++: #include<cstdio>

int main(){
	int money;
	int dat[] = {500,100,50,10,5,1};

	while(1){
		scanf("%d",&money);
		if(money == 0)break;
		int fishing = 1000-money;
		int cnt = 0;
		
		for(int i=0;i<6;++i){
			if(fishing < 0)break;
			int tmp = fishing/dat[i];
			fishing -= tmp * dat[i];
			cnt += tmp;
		}

		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num = 0;
	
	while (scanf("%d", &price), price){
		scanf("%d", &price);
		back = PAY - price;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d", num);
	}
	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>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int M[] = {500, 100, 50, 10, 5, 1};

int main(void){
    for(int m, cnt; cin >> m, cnt = 0, m; cout << cnt << endl)
        rep(i, 6) while(m + M[i] <= 1000) m += M[i], cnt ++;
 
    return 0;
}

C++: #include<iostream>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main() {int n,r,i;while(1){cin>>n;if(!n)break;n=1000-n,r=0;for(i=0;i<6;i++)r+=n/coin[i],n%=coin[i];cout<<r<<endl;}}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int a,b,c=0;
	cin >> a;
	b=1000-a;
	c+=b/500;
	b=b%500;
	c+=b/100;
	b=b%100;
	c+=b/50;
	b=b%50;
	c+=b/10;
	b=b%10;
	c+=b/5;
	c+=b%5;
	cout << c << endl;
	
	return 0;
}

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int count=0,money=1000-n;
		while(money>=500)money-=500,count++;
		while(money>=100)money-=100,count++;
		while(money>=50)money-=50,count++;
		while(money>=10)money-=10,count++;
		while(money>=5)money-=5,count++;
		while(money>=1)money-=1,count++;
		std::cout<<count<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int coin[6] = {500,100,50,10,5,1};
	int money;
	while(cin >> money){
		int sum=0;
		money=1000-money;
		for(int i=0; i<6; i++){
			int count=0;
			if(money >= coin[i]){
				count+=money/coin[i];
				money-=coin[i]*count;
			}
			sum+=count;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
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;
return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	int n;
	while (cin >> n)
	{
		if (n == 0)
		{
			break;
		}

		n = 1000 - n;

		int ans = 0;
		int x[] = {500, 100, 50, 10, 5, 1};
		for (int i = 0; i < 6; i++)
		{
			int add = n / x[i];
			ans += add;

			n -= add * x[i];
			if (n <= 0)
			{
				break;
			}
		}

		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

void main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n",ans);
  return 0;
}

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

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