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>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent ;
 
    
    }
    return 0;

}

C++: #include<iostream>

using namespace std;

void Calculate(int, int&, int&);

int main(){
  int n, m, count;

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

    n = 1000 - n;
    count = 0;

    Calculate(500, n, count);
    Calculate(100, n, count);
    Calculate(50, n, count);
    Calculate(10, n, count);
    Calculate(5, n, count);
    Calculate(1, n, count);

    cout << count << endl;
  }

  return 0;
}

void Calculate(int m, int& n, int& count){
  int x;

  while(1){
    x = n - m;
    if(x < 0) break;
    ++count;
    n = x;
  }
}

C++: #include <cstdio>

using namespace std;

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a = 0;
	int b;
	int c = 0;
	for (; a != 0;)
	{
		cin >> a;
		b = a;
		for (; b != 0;)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			if (b >= 1)
			{
				b = b - 1;
				c++;
			}
			cout<<c<<endl
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


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

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

int main(){

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

	scanf("%d", &pay);

	if(pay == 0) return 0;

	change = 0;
	money = 1000 - pay;

	for(int i = 0; i < 6; i++){

		change += money / c[i];
		money = money % c[i];
	}

	printf("%d\n", change);

	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  while(cin>>n,n){
    n=1000-n;
    int a[]={500,100,50,10,5,1};
    int ans=0;
    for(int i=0;i<6;i++){
      while(n>=a[i]) n-=a[i],ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;

int main()
{int n, A, ans=0;
while(cin >> n, n){ans=0; A = 1000 - n;
int C[6]={500, 100, 50, 10, 5, 1};
rep(i, 6)
{ans += A/C[i]; A %= C[i];}
cout << ans << endl;}

       
 }

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

int main(){

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

	return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
  int turi;
  int hara;
  int count;
  while(1){
    count=0;
    cin>>hara;
    if(hara==0) break;
    turi=1000-hara;
    while(turi!=0){
      if(turi>=500){
	turi=turi-500;
	count++;
      }
      else if(turi>=100){
	turi=turi-100;
	count++;
      }
      else if(turi>=50){
	turi=turi-50;
	count++;
      }

      else if(turi>=10){
	turi=turi-10;
	count++;
      }
      else if(turi>=5){
	turi=turi-5;
	count++;
      }
      else if(turi>=1){
	turi=turi-1;
	count++;
      }
    }
    cout<<count<<endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	while(true){
		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++: #include<bits/stdc++.h>
using namespace std;
const int V[6]={1,5,10,50,100,500};
int C[6],A;

void 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);
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int main()
{
	int N;
	int coin[7]={500,100,50,10,5,1};

	while(1)
	{
		int count=0;
		int j=0;

		s_1(N);
		if(N==0)break;
		int max_c=1000-N;
		
		while(max_c>0)
		{
			rep_to(j,i,6)
			{
				if(coin[i]<=max_c)
				{
					max_c-=coin[i];
					count++;
					break;
				}
				else j++;
			}
		}
		cout<<count<<endl;
	}
	
	return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1<0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;

   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
   }
 }
   
  return 0;
}

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