Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"bufio"
)

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}

C++: #include <iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

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

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

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

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

int main(void){
	int n;
	while(cin >> n && n){
		int v = 1000 - n;
		int ret = 0;
		int c[] = {500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			ret += v / c[i];
			v -= (v/c[i])*c[i];
		}
		cout << ret << endl;
	}
}

C++: #include <iostream>

int main() {
	int a,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;




}

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

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

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

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s)begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) (a).begin(), (a).end()

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//------------------HEAD---------------------

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

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

C++: #include <iostream>
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 <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

constexpr int INF = 1e9;

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

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout << b/500+c/100+d/50+e/10+f/5+g << endl;
	
	return 0;
}

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

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

C++: #include<stdio.h>
int main(void)
{
	int a,s,s1;
	while(1){
		scanf("%d",&a);
		if(a==0)break;
		s=1000-a;
		s1=s/500;
		s=s%500;
		s1+=s/100;
		s=s%100;
		s1+=s/50;
		s=s%50;
		s1+=s/10;
		s=s%10;
		s1+=s/5;
		s=s%5;
		s1+=s/1;
		printf("%d\n",s1);
	}
	
	return 0;
}

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	for(int i=0;i<150;i++){
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	}
	return 0;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a, b;
	while(cin >> a){
		b = 1000 - b;
		int ret = 0;
		while(b != 0){
			if(b >= 500){
				ret++;
				b -= 500;
			}else if(b >= 100){
				ret += b/100;
				b %= 100;
			}else if(b >= 10){
				ret += b/10;
				b %= 10;
			}else if(b >= 5){
				ret += b/5;
				b %= 5;
			}else{
				ret += b;
				b = 0;
			}
		}
		cout << ret << endl;
	}

	return 0;
}

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