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>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        int v = 1000 - n;
        int coins[] = {500, 100, 50, 10, 5, 1};
        int pos = 0, ans = 0;
        while(v > 0)
        {
            while(v - coins[pos] < 0) pos++;
            v -= coins[pos];
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt=0,div[6]={500,100,50,10,5,1},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<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  int n,ans;
  int m[6]={500,100,50,10,5,1};
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    ans=0;
    n=1000-n;
    for(int i=0;i<6;i++){
      ans+=n/m[i];
      n%=m[i];
    }
    printf("%d\n",ans);
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>
#include <complex>
#include <vector>
#include <functional>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
#define INF 100000000
typedef pair<int,int> P;
int coin[]={500,100,50,10,5,1};
int main()
{
	int n;
	while(scanf("%d",&n)&&n){
		int ans=0;
		n=1000-n;
		for(int i=0;i<6;i++){
			ans+=n/coin[i];
			n%=coin[i];
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

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

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

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

int main(){
	int many=0,ans=0,count=0;
	
	cin >> many ;
	ans=1000-many;
	count+=ans/500;ans=ans%500;
	count+=ans/100;ans=ans%100;
	count+=ans/50;ans=ans%50;
	count+=ans/10;ans=ans%10;
	count+=ans/5;ans=ans%5;
	count+=ans/1;ans=ans%1;
	
	printf("%d\n",count);
}

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

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

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

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

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

int main(void){
    // Your code here!
    int tmp;
    while(cin>>tmp){
        if(tmp == 0){
            break;
        }
        int sum = 1000 - tmp;
        int cnt = 0;
        int s = 0;
        bool flag = false;
        while(true){
            if(sum == 0){
                flag = true;
                break;
            } else if(sum - coin[s] >= 0){
                sum -= coin[s];
                cnt += 1;
            } else{
                s++;
            }
            
        }
        
        cout << cnt << endl;

    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int co = 0;
		int a = 0;
		cin >> a;
		if (a == 0)
		{
			break;
		}

		int o = 0;
		o = 1000 - a;
        for (int i = 0; i < 100; i++)
        {
	        if (o == 0)
	        {
		        break;
	        }
	        if (o >= 500)
		    {
			    co++;
			    o -= 500;
		    }
		    else if (o >= 100)
		    {
			    co++;
			    o -= 100;
		    }
		    else if (o >= 50)
		    {
			    co++;
			    o -= 50;
		    }
		    else if (o >= 10)
		    {
			    co++;
			    o -= 10;
		    }
		    else if (o >= 5)
		    {
			    co++;
			    o -= 5;
		    }
		    else if (o >= 1)
		    {
			    co++;
			    o -= 1;
		    }
        }
		cout << co << endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>
#include<chrono>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define timenow std::chrono::system_clock::now()
#define timecal(start,end) std::chrono::duration_cast<std::chrono::milliseconds>((end)-(start)).count()

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))


constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  if(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  if(n >= 5){
    n -=5;
    ++ans;
  }
  cout << ans + n << endl;
  return 0;
}

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

const int data[6]={500,100,50,10,5,1};
int main() {
	// your code goes here
	int n;
	while(cin>>n && n){
		n=1000-n;
		int ans=0;
		for(int i=0;i<6;i++){
			ans+=n/data[i];
			n%=data[i];
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num;
	
	while (scanf("%d", &price), price){
		back = PAY - price;
		num = 0;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d\n", num);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
 
  while(true){
   int t;
 cin>>t;
   if(t==0){
   break;
   }
   
 
 int s=1000-t;
 int w=s/500;
 int e=(s%500)/100;
  int r=((s%500)%100)/50;
  int y=(((s%500)%100)%50)/10;
  int u=((((s%500)%100)%50)%10)/5;
  int o=(((((s%500)%100)%50)%10)%5);
  cout<< w+e+r+y+u+o <<endl;
}
  
}