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()
{
	for(;;){
	int kane, sub, cont = 0;
	
	cin >> kane;
	if(kane == 0){
		break;
	}
	
	kane = 1000 - kane;
	sub = kane;
	for(;;){
		if(sub - 500>= 0){
			cont++;
			sub -= 500;
		}
		else{
			break;
		}
	}
//	cout <<"500:" << cont << endl;
	for(;;){
		if(sub - 100 >= 0){
			cont++;
			sub -= 100;
		}
		else{
			break;
		}
	}
//	cout <<"100:" <<cont<< endl;
	for(;;){
		if(sub - 50 >= 0){
			cont++;
			sub -= 50;
		}
		else{
			break;
		}
	}
	
//	cout << "50:" << cont << endl;
	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 5 >= 0){
			cont++;
			sub -= 5;
		}
		else{
			break;
		}
	}
	
	for(;;){
		if(sub - 1 >= 0){
			cont++;
			sub -= 1;
		}
		else{
			break;
		}
	}
	
	cout << cont << endl;
}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int c[]={500,100,50,10,5,1};
int main(){
    int n;
    while(cin>>n,n){
        int ret=0,m=1000;
        while(m>n){
            rep(i,6){
                if(m-c[i]>=n){
                    m-=c[i];
                    ret++;
                    break;
                }
            }
        }
        cout<<ret<<endl;
    }
}

C++: #include<iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		n=1000-n;
		int m=0;
		m+=n/500;	n-=n/500*500;
		m+=n/100;	n-=n/100*100;
		m+=n/50;	n-=n/50*50;
		m+=n/10;	n-=n/10*10;
		m+=n/5;		n-=n/5*5;
		m+=n;
		cout<<m<<endl;
	}
	return 0;
}

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

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

C++: #include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,asum=0,bsum=0;
	for(int i=0;i<4;i++)
	{
		cin>>a;
		asum+=a;
	}
	for(int i=0;i<4;i++)
	{
		cin>>b;
		bsum+=b;
	}
	if(asum>=bsum)
		cout<<asum<<endl;
	else
		cout<<bsum<<endl;
	return 0;
}

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

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

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	int a, b, c, d, e, i, j, k, l, m, n, o, p, q, r;
	cin >> a;
	if (a > 0)
	{
		c = 0;
		a = 1000 - a;
		b = a;
		b = a / 500;
		c = c + b;
		a = a % 500;
		b = a / 100;
		c = c + b;
		a = a % 100;
		b = a / 50;
		c = c + b;
		a = a % 50;
		b = a / 10;
		c = c + b;
		a = a % 10;
		b = a / 5;
		c = c + b;
		a = a % 5;
		b = a;
		c = c + b;
		cout << c << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int mian(void){
	int n,k;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		k += n /500;  n %=500;
		k += n/100;   n %=100;
		k += n/50;    n %= 50;
		k += n/10;    n %= 10;
		k += n/5;     k += n%5;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

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

using namespace std;

int main(void) {	
	int n;
	while (cin >> n && n > 0) {
		int ans = 0;
		n = 1000 - n;
		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;
		
		cout << ans << endl;
		
	}
				  
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	if(n>=500){
		m = n/500;
		n = n%500;
	}
	if(n>=100){
		m = m+n/100;
		n = n%100;
	}
	if(n>=50){
		m = m+n/50;
		n = n%50;
	}
	if(n>=10){
		m = m+n/10;
		n = n%10;
	}
	if(n>=5){
		m = m+n/5;
		n = n%5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

        return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

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

C++: #include<stdio.h>
int main()
{
	int cnt=0, a, b, i, j;
	scanf("%d", &a);
	while (1) {
		if (a >= 500) {
			a = a - 500;
			cnt++;
		}
		else if (a >= 100) {
			a = a - 100;
			cnt++;
		}
		else if (a >= 50) {
			a = a - 50;
			cnt++;
		}
		else if (a >= 10) {
			a = a - 10;
			cnt++;
		}
		else if (a >= 1) {
			a = a - 1;
		}
		if (a == 0) {
			break;
		}
	}
	printf("%d\n", cnt);
}

C++: #include<cstdio>
using namespace std;
int money[6]{500,100,50,10,5,1};
void solve(int price){
  int ans{0};
  for(int i{0} ; i< 6 ; i++){
    while(price >= money[i]){
      price -= money[i];
      ans++;
    }
  }
  printf("%d\n",ans);
}
int main(){
  int price;
  while(true){
    scanf("%d",&price);
    if(price == 0)
      break;
    solve(1000 - price);
  }
}

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

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

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

int main(){
cin >> n;
n = 1000-n;
for( int i = 5; i >= 0; i-- ){
while(n>=change[i]){
n-=change[i];
cnt[i]++;
}
}
int ans=0;
for(int i = 0; i < 6; i++ )
ans += cnt[i];
cout << ans << endl;
return 0;
}