Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int mo,fite,hund,fiten,ten,go,one;
    while(1){
    cin>>mo;
    if(mo==0)break;
    mo=1000-mo;
    fite=mo/500;
    hund=mo%500/100;
    fiten=mo%500%100/50;
    ten=mo%500%100%50/10;
    go=mo%500%100%50%10/5;
    one=mo%500%100%50%10%5;
    //cout<<fite<<" "<<hund<<" "<<fiten<<" "<<ten<<" "<<go<<" "<<one<<"\n";
    cout<<fite+hund+fiten+ten+go+one<<"\n";
}
}

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

int main() {
    int Y, C[6] = {500, 100, 50, 10, 5, 1};
    while (cin >> Y) {
        if (Y == 0) break;
        int ans = 0, charge = 1000 - Y;
        for (int i = 0; i < 6; ++i) {
            int t = charge / C[i];
            charge -= t * C[i];
            ans += t;
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

int K(int a){
int p = 0;
if(a >= 500){
a = a-500;
p = p+1;
}
while(a>=100){
a = a-100;
p = p+1;
}
if(a >= 50){
a = a-50;
p = p+1;
}
while(a>=10){
a = a-10;
p = p+1;
}
if(a >= 5){
a = a-5;
p =p+1;
}
p = p+a;
return p;
}
int main() {
while(1){
int buy = 0;int maisuu = 0;
cin >> buy;
if(buy == 0){break;}
buy = 1000 - buy;
cout <<  K(buy) << endl;
}
	return 0;
}

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

C++: #include <bits/stdc++.h>

using namespace std;

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;

	cin >> in;

	change = 1000 - in;

	for (int i = 0; i < 6; i++) {
		while (change >= coin[i]) {
			change -= coin[i];
			n++;
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

C++: #include <iostream>
int main()
{
	int n;
	while(std::cin>>n,n){
		n = 1000-n;
		int ans = 0;
		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++;
		}
		ans += n;
		printf("%d\n",ans);
	}
	return 0;
}

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	int a = 1000 - n;
	int cnt = 0;
	for(int i = 0; i < 6; ++i){
		while(a >= coin[i]){
			a -= coin[i];
			++cnt;
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){

  int a;
  cin >> a;
  while(a != 0){
    
    int coin = 0;
    a = 1000-a;

    if(a>=500){
      coin++;
      a-=500;
    }
    while(a>=100){
      coin++;
      a -= 100;
    }
    if(a>=50){
      coin++;
      a-=50;
    }
    while(a>=10){
      coin++;
      a-=10;
    }
    if(a>=5){
      coin++;
      a-=5;
    }
    cout << coin+a << endl;
    cin >> a;
  }

  return (0);
}

C++: #include "bits/stdc++.h"
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> coin = {500,100,50,10,5,1};
  while(n/*!=0はなくても意味が同じ*/){
    n = 1000 - n;
    int ans = 0;
    for(int i=0;i<6;++i){
      ans += n / coin.at(i);
      n %= coin.at(i);
    }
    cout << ans << endl;
    cin >> n;
  }
}

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>
#include <vector>

const std::vector<int> ms{500, 100, 50, 10, 5, 1};

bool solve() {
    int n;
    std::cin >> n;
    if (n == 0) return false;

    n = 1000 - n;
    int ans = 0;
    for (auto m : ms) {
        ans += n / m;
        n %= m;
    }

    std::cout << ans << "\n";

    return true;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    while (solve()) {}

    return 0;
}

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

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

int main(void){
	int mon, cnt;
	while(true){
		cin >> mon;
		if(mon == 0)	break;
		mon = 1000 - mon;
		cnt = 0;
		for(int i = 0; i < 6; i++){
			if(mon == 0)	break;
			cnt += mon / change[i];
			mon -= change[i] * (mon / change[i]);
		}
		cout << cnt << endl;
	}
  return 0;
}

C++: #include <iostream>

using namespace std;

int coin;

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

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num = 0;
	cin >> pay;
	pay = 1000 - pay;
	if (pay / 500 == 1){
		pay -= 500;
		num++;
	}
	for (;;){
		if (pay / 100 >= 1){
			pay -= 100;
			num++;
		}
		else break;
	}
	for (;;){
		if (pay / 50 >= 1){
			pay -= 50;
			num++;
		}
		else break;
	}
	for (;;){
		if (pay / 10 >= 1){
			pay -= 10;
			num++;
		}
		else break;
	}
	for (;;){
		if (pay >= 5){
			pay -= 5;
			num++;
		}
		else break;
	}
	for (;;){
		if (pay>= 1){
			pay -= 1;
			num++;
		}
		else break;
	}
	cout << num << endl;	
}

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

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

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

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

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

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

void kesan(int, int*, int*);
int main(){
  int n, i , j, a;
  while(true){
    cin >> n;
    a = 0;
    if(!n)
      break;
    n = 1000 - n;
    kesan(500, &a, &n);
    kesan(100, &a, &n);
    kesan(50, &a, &n);
    kesan(10, &a, &n);
    kesan(5, &a, &n);
    a += n;

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

void kesan(int coin, int *a, int *n){
  int i = *n / coin;
  *a += i;  
  *n -= i * coin;
}