Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m,a,b,c,d,e,f;
	cin>>n;
	m=1000-n;
	for(a=0;a<2;a++){
	    for(b=0;b<5;b++){
			for(c=0;c<2;c++){
				for(d=0;d<5;d++){
					for(e=0;e<2;e++){
						for(f=0;f<5;f++){
							if(a*500+b*100+c*50+d*10+e*5+f*1==m){
								cout<<a+b+c+d+e+f<<endl;
								break;
                            }
							}
						}
					}
				}
			}
	    }
	return 0;
	}

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

C++: #include <stdio.h>

int main(void) {
	int m,c = 0;
		while (scanf("%d",&m) , m != 0){
			c = 0;
			m = 1000 - m;
			while(m >= 500 ){
				m = m - 500 ;
				c++;
			}
			while(m >= 100 ){
				m = m - 100 ;
				c++;
			}
			while(m >= 50 ){
				m = m - 50 ;
				c++;
			}
			while(m >= 10 ){
				m = m - 10 ;
				c++;
			}
			while(m >= 5 ){
				m = m - 5 ;
				c++;
			}
			while(m){
				m--;
				c++;
			}
			printf ("%d\n",c);
		}
	return 0;
}

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

int main(){
	int m,t;
	int p=0;
	cin >> m;
	if(m==0){
		break;
	}
	t=1000-m;
	while(1){
	if(t>=500){
	t-=500;	
	p++;
	}else if(t>=100){
	t-=100;
	p++;
	}else if(t>=50){
	t-=50;
	p++;
	}else if(t>=10){
	t-=10;
	p++;
	}else if(t>=5){
	t-=5;
	p++;
	}else{
	t--;
	p++;
		}
	if(t==0){
		break;
	}	
	}
	cout << p << '\n';
	count=0;
	
	return 0;
}

C++: #include <stdio.h>

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

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

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

}

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

int main(){
int total;
int change;
int count=0;
while(true){
 cin>>total;
 if(total==0){
    break;
  } 
 change=1000-total;
 while(true){
   if(change>=500){
     change-=500;
     count++;
   }else if(change>=100){
     change-=100;
     count++;
   }else if(change>=50){
     change-=50;
     count++;
   }else if(change>=10){
     change-=10;
     count++;
   }else if(change>=5){
     change-=5;
     count++;
   }else{
     change--;
     count++;
    }
  if(change==0){
    break;
  }
 }
 cout<<count<<"\n";
 count=0;
}
return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		N = 1000 - N;
		int ans = 0;
		vector<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N %= m;
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

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

C++: #include<stdio.h>
int main()
{
	int n,r,i,f;
	for(i=0;i<5;i++){
		r=0;
		scanf("%d",&f);
		if(f==0){
			break;
		}
		n=1000-f;
		if(n>=500){
			r++;
			n-=500;
		}
		while(n>=100){
			r++;
			n-=100;
		}
		if(n>=50){
			r++;
			n-=50;
		}
		while(n>=10){
			r++;
			n-=10;
		}
		if(n>=5){
			r++;
			n-=5;
		}
		while(n>0){
			r++;
			n-=1;
		}
		printf("%d\n",r);
	}

	return 0;
}

C++: #include<iostream>


using namespace std;
int main(void){
    int a;
	int n;
	int c=0;
	cin>>a;

	int count=0;
	for(n=1000-a;n!=0;c++){
        if(n>=500)n-=500;
        else if(n>=100)n-=100;
        else if(n>=50)n-=50;
        else if(n>=10)n-=10;
        else if(n>=5)n-=5;
        else if(n>=1)n-=1;
    }
    cout << c << endl;


	return 0;
}

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

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

int main(){

    int input,money,ans;

    while(1){
      cin >> input;
      if(input == 0){
        break;
      }
      money = 1000 - input;

      ans = 0;

      for(int i=0;i<6;i++){
        ans += money/coin[i];
        money = money % coin[i];
        if(money==0){
          break;
        }
      }
      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 s[6]={500,100,50,10,5,1};
	while(cin>>n,n!=0){
	int x=0;
	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<bits/stdc++.h>

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

C++: #include <iostream>
using namespace std;
main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 10){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy;
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
return 0;
}

C++: #include<iostream>
#include<utility>
#include<queue>

using namespace std;

int main(void){

	std::ios_base::sync_with_stdio();

	int kouka[]={500,100,50,10,5,1};
	int n,cnt;

	while(1){
		cin>>n;
		if(n==0) break;
		n=1000-n;
		cnt=0;
		for(int i=0;i<6;i++){
			cnt+=n/kouka[i];
			n-=(n/kouka[i])*kouka[i];
		}
		cout<<cnt<<endl;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  while(1){
    int in;
    cin >> in;
    if(in == 0) break;

    int money = 1000;
    money -= in;

    int sum = 0;

    if(money >= 500){
      sum++;
      money -= 500;
    }

    while(money >= 100){
      sum++;
      money -= 100;
    }

    if(money >= 50){
      sum++;
      money -= 50;
    }

    while(money >= 10){
      sum++;
      money -= 10;
    }

    if(money >= 5){
      sum++;
      money -= 5;
    }

    sum += money;

    cout << sum << endl;

  }

  return 0;
}