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<bits/stdc++.h>
using namespace std;

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

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

C++: #include <cstdio>
using namespace std;
int main()
{
 while(1){
  int a;
  scanf("%d",&a);
 if(a==0) return 0;
  a=1000-a;
  printf("%d\n",a/500+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);
 }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

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

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

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

int main(){
	while(1){
		int n, p=1000, ans=0, i=0;
		int m[6]={500, 100, 50, 10, 5, 1};
		
		scanf(" %d", &n);
		if(n==0) break;
	
		p-=n;
		for(int i=0; i<6; ++i){
			if(p>=m[i]){
				int t=p/m[i];
				ans+=t;
				p-=m[i]*t;
			}			
		}
	
		printf("%d\n", ans);
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h;
    
    
    while(cin>>a){
        if(a==0){
            break;
        }
            b=1000-a;
            c=b/500;
            d=(b%500)/100;
            e=((b%500)%100)/50;
            f=(((b%500)%100)%50)/10;
            g=((((b%500)%100)%50)%10)/5;
            h=(((((b%500)%100)%50)%10)%5)/1;
            
            cout<<c+d+e+f+g+h<<endl;
    }
        
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

int main(){
	while(1){
		int n; cin >>n;
		if(n==0)break;
		int m=1000-n;
		cout << m/500+m%500/100+m%100/50+m%50/10+m%10/5+m%5/1 << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num_answer = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num_answer = 0;

		if (cost_return >= 500) {
			++num_answer;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num_answer;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num_answer;
			cost_return -= 50;
		}
		while (1)
		{
			if (cost_return >= 10) {
				++num_answer;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num_answer;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num_answer;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
	}
	

	for (int i = 0; i < j;++i) {
		CO num_answer E
	}
}

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

int count(int x,int c){
   if(x>=500){
       return count(x-500,c+1);
   }
   if(x>=100){
       return count(x-100,c+1);
   }
   if(x>=50){
       return count(x-50,c+1);
   }
   if(x>=10){
       return count(x-10,c+1);
   }
   if(x>=5){
       return count(x-5,c+1);
   }
   if(x==0){
       return c;
   }
   else{
       return count(x-1,c+1);
   }
}
int main(void){
   int x;
   while(true){
       cin >> x;
       if(x==0){
           break;
       }
       cout << count(1000-x,0)<< endl;
   }
}

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num[10];
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num[i] = 0;

		if (cost_return < 5) {
			num[i] = cost_return;
			continue;
		}
		else {
			if (cost_return < 10) {
				num[i] = 1 + cost_return - 5;
				continue;
			}
		}


		if (cost_return >= 500) {
			++num[i];
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num[i];
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num[i];
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num[i];
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num[i];
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num[i];
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
		
	}
	
	for (int i = 0; i < j; ++i) {
		CO num[i] E
	}

	
}

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

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

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

int main() {
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int v[] = {500, 100, 50, 10, 5, 1};

        int ans = 0;
        for (int i = 0; i < 6; i++) {
            ans += N / v[i];
            N %= v[i];
        }

        cout << ans << endl;
    }

    return 0;
}