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() {
    ios::sync_with_stdio(false);
    int a[5];
    for (int i = 0; i < 5; i++) cin >> a[i];
    
    for (int i = 0; i < 5; i++) {
        
        if (a[i] == 0) break;
        
        int count = 0;
        int n = 1000-a[i];
        while (n % 500 == 0) {
            n -= 500;
            count++;
        }
        while (n % 100 == 0) {
            n -= 100;
            count++;
        }
        while (n % 50 == 0) {
            n -= 50;
            count++;
        }
        while (n % 10 == 0) {
            n -= 10;
            count++;
        }
        while (n % 5== 0) {
            n -= 5;
            count++;
        }
        count += n;
        
        cout << count << endl;
    }
    
    return 0;
}

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

int main(){
	for(int i=0; i<5; i++){

		int C;
		
		cin >> C ;


		cout << (1000-C)/500 + (1000-C)/100-5*((1000-C)/500) + 
				(1000-C)/50-2*((1000-C)/100) + (1000-C)/10-5*((1000-C)/50) +
				(1000-C)/5-2*((1000-C)/10) + (1000-C)-5*((1000-C)/5) << endl;
	}



}

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

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

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

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

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		n=1000-n;
		int res=0;
		res+=n/500;
		n-=n/500*500;
		res+=n/100;
		n-=n/100*100;
		res+=n/50;
		n-=n/50*50;
		res+=n/10;
		n-=n/10*10;
		res+=n/5;
		n-=n/5*5;
		res+=n;
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (oturi >= a[i]){
			div_t d;

			d = div(oturi, a[i]);
			oturi = oturi - a[i] * d.quot;
			count = count + d.quot;
		}
	}
	printf("%d\n",count);

	return 0;

	div(20, 3);

}

C++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

int main(){
  int ans=0;
  for(int i=5;i>=0;i--){
    int t=min(A/V[i],C[i]);
    A-=t*V[i];
    ans+=t;
  }
  printf("%d\n",ans);
  return 0;
}

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

using namespace std;

int coin[10] = {0, 1, 2, 3, 4, 1, 2, 3, 4, 5};

int main(){
	int n, ans;
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		n = 1000 - n;
		ans = 0;
		for(int loop = 0; loop < 4; loop++){
			ans += coin[n % 10];
			n /= 10;
		}
		
		printf("%d\n", ans);
	}
	return 0;
}

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>
using namespace std;
int main(){
int price,cnt=0;
int div[6]=[500,100,50,10,5,1];
int i;
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
for(i=0;i<6;i++){
if((price/div[i])!=0){
cnt+=(price/div[i]);
price-=(price/div[i])*div[i];
}
}
cout<<cnt<<endl;
cnt=0;
}
return 0;
}

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

int main() {
	while (1) {
		int all = 0 , rem = 0, count = 0, tmp  = 0;
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
	}
	return 0;
}

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

int a,sum,ans,dx[6]={500,100,50,10,5,1};

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

    for(int i=0;i<6;i++){
    ans=a/dx[i];
    sum=sum+ans;
    a=a%dx[i];
    ans=0;
    }

    cout << sum << endl;
    sum=0;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int n;
	int i;
	int a[5];
	for(i = 0; i < 5; i++){
		scanf("%d",&n);
		if(n == 0) break;
			a[i] = n;
	}
	
	for(int j = 0; j < i; j++){
		int val = 1000 - a[j];
		int count = 0;
		count += val / 500;
		val -= 500 * (val / 500);
		count += val / 100;
		val -= 100 * (val / 100);
		count += val / 50;
		val -= 50 * (val / 50);
		count += val / 10;
		val -= 10 * (val / 10);
		count += val / 5;
		val -= 5 * (val / 5);
		count += val;
		
		printf("%d\n", count);
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>


int main(void) {
	int num,n,i,a,b;
	a=0,b=0;
	scanf("%d",&num);
	n=1000-num;

	if (n>500) {
		i++;
		n=(n-500);
	}
	if (n>100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>50){
		i++;
		n=(n-50);
	}
	if (n>10){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>5){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	return 0;
}