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>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(a!=0){b=1000-a;
c=0;
if(b>=500){b=b-500; c=c+1;}
if(b>=100){while(b<100){b=b-100; c=c+1;}}
if(b>=50){b=b-50; c=c+1;}
if(b>=10){while(b<10){b=b-10; c=c+1;}}
if(b>=5){b=b-5; c=c+1;}
c=b+c;
cout << c<<endl;
}
}
}

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

C++: #include<stdio.h>

int main(){
	int a;
	int b;
	int c = 0;
	scanf("%d", &a);
	b = 1000;
	b -= a;
	int d;
		
	while(b != 0){
		if(b == 0){
			break;
		}else if(b > 500){
			b -= 500;
		}else if(b > 100){
			b -= 100;
		}else if(b > 50){
			b -= 50;
		}else if(b > 10){
			b -= 10;
		}else if(b > 5){
			b -= 5;
		}else{
			b--;
		}
		c++;
		
	}
	printf("%d\n", c);

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    while(1){
        int x;
        cin >> x;
        if(x == 0)break;
        x = 1000 - x;
        
        int ans = 0;
        ans += x/500;
        x %= 500;
        ans += x/100;
        x %= 100;
        ans += x/50;
        x %= 50;
        ans += x/10;
        x %= 10;
        ans += x/5;
        x %= 5;
        ans += x;
        cout << ans << endl;
    }
    return 0;
}

C++: // 2011/12/01 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){

	int n;
	cin >> n;

	if(n==0)
		break;

	int m = 1000-n;

	int sum = 0;

	sum += m/500;
	m %= 500;

	sum += m/100;
	m %= 100;

	sum += m/50;
	m %= 50;

	sum += m/10;
	m %= 10;

	sum += m/5;
	m %= 5;

	sum += m;

	cout << sum << endl;

	}

	return 0;
}

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

C++: #include <iostream>
using namespace std;
 
int main() {
    // your code goes here
    int n;
    while(cin >> n && n!=0){
        n=1000-n;
        int sum=0;
        int coin[]={500,100,50,10,5,1};
        for(int i=0;i<6;i++)
            while(n>=coin[i]){
                sum++;
                n-=coin[i];
            }
    cout << sum << endl;
    }
    return 0;
}

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

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

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int x=0;
	int s[6]={500,100,50,10,5,1};
	cin>>n;
	
	n=1000-n;
	int k=0;
	while(n>0){
		if(n-s[k]>=0){
			n=n-s[k];
			x++;
		}
		else
			k++;
	}
	
	cout<<x<<endl;
	

}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int main() {
  while (1) {
    int in;
    cin >> in;
    if (in == 0) break;
    int n = 1000 - in;

    int c = 0;
    c += n / 500;
    n %= 500;

    c += n / 100;
    n %= 100;

    c += n / 50;
    n %= 50;

    c += n / 10;
    n %= 10;

    c += n / 5;
    n %= 5;

    c += n / 1;
    n %= 1;

    println(str(c));
  }
  return 0;
}

C++: #include <stdio.h>
int main(void){
  int n,ans=0;
  scanf("%d",&n);
  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;
  printf("%d\n",ans+n%5);
  
}

C++: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> bills = {500, 100, 50, 10, 5, 1};
    int n;
    while(cin >> n and n) {
        int change = 1000 - n;
        int ans = 0;
        for(int bill : bills) {
            while(change >= bill) {
                change -= bill;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

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

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


int main() {
	int coin[6]={500,100,50,10,5,1},price,sum;
	while (true)
	{
	    scanf("%d",&price);
		if (price == 0) break;
		sum =0;
		price = 1000-price;
		for (int i = 0; i <= 5; i++)
		{
				while (price>=coin[i]) {
					price-=coin[i];
					sum++;
				}



		}
		printf("%d\n", sum);
	}




	
	return 0;
}

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

	int m, count;

	cin >> m;

	while (m != 0){
		count = 0;
		m = 1000 - m;
		if (m >= 500){
			count += m / 500;
			m /= 500;
		}
		if (m >=100){
			count += m / 100;
			m /= 100;
		}if (m >= 50){
			count += m / 50;
			m /= 500;
		}if (m >= 10){
			count += m / 10;
			m /= 50;
		}if (m >= 5){
			count += m / 5;
			m /= 5;
		}
		count += m;

		cout << count << endl;

		cin >> m;
	}

}