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() {  
  int x;   
  while(1) { 
    int count=0;  
    cin >> x;
    if(x==0) break;  
    x = 1000-x; 
    count += x/500;  
    x = x%500;   
    count += x/100;  
    x = x%100;   
    count += x/50;  
    x = x%50;   
    count += x/10;  
    x = x%10;   
    count += x/5;
    x = x%5;  
    count += x/1;  
    cout << count << endl;
  } 
  return 0;
}

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

using namespace std;

int main() {
    int n;
    
    while (cin >> n, n) {
        n = 1000 - n;

        int a = n / 500;
        n %= 500;

        int b = n / 100;
        n %= 100;

        int c = n / 50;
        n %= 50;

        int d = n / 10;
        n %= 10;

        int e = n / 5;
        int f = n % 5;

        int ans = a + b + c + d + e + f;
        cout << ans << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(){
  
  while(1){
    
    int n,cnt=0;
  
  scanf("%d",&n);
  
  if(n==0){break;}

  n=1000-n;
  
  while(n>=500){
    n-=500;
    cnt++;
  }
  while(n>=100){
    n-=100;
    cnt++;
  }
  while(n>=50){
    n-=50;
    cnt++;
  }
  while(n>=10){
    n-=10;
    cnt++;
  }
  while(n>=5){
    n-=5;
    cnt++;
  }
  while(n!=0){
    n--;
    cnt++;
  }

  printf("%d\n",cnt);
  
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll n,ans;
vector<int> abcd(4);

  
int main(){
  vector<int> price={500,100,50,10,5,1};
  while(1){
    int x;
    cin >> x;
    if(x==0)break;
    int y = 1000-x;
    int coins=0;
    rep(i,6){
      int t = y/price[i];
      y -= t*price[i];
      coins += t;
    }
    cout << coins << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,o,s,m;
	
	scanf("%d",&m);
	while(m!=0){
		a=0;
		b=0;
		c=0;
		d=0;
		e=0;
		f=0;
		s=0;
		
		o=1000-m;
		a=o/500;
		o=o-500*a;
		b=o/100;
		o=o-100*b;
		c=o/50;
		o=o-50*c;
		d=o/10;
		o=o-10*d;
		e=o/5;
		o=o-5*e;
		f=o/1;
		o=o-1*f;
	
	s=a+b+c+d+e+f;
	
	printf("%d\n",s);
	scanf("%d",&m);
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

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

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

int memo[1111];
int p[] = {500, 100, 50, 10, 5, 1};

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  for(int i=0;i<6;i++) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

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

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

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

int main()
{
    int n;
    while(cin >> n && n)
    {
        int ans = 0;
        n = 1000 - n;

        REP(MAXC)while(n >= coin[i]){ n-= coin[i]; ans++;}
        
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

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

	return 0;
}

C++: #include <stdio.h>

int main() {
    while (1) {
        int i;
        int value, change;
        int array[6] = {500, 100, 50, 10, 5, 1};
        int times = 0; 
        int tmp;

        scanf("%d", &value);
        if (!value) return 0;

        change = 1000 - value;

        tmp = change;
        for (i=0;i<6;i++) {
            times += (tmp/array[i]);
            tmp %= array[i];
        }

        printf("%d\n", times);
    }
}

C++: #include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	for(;;){
		int a,b=0,c=0;
		cin>>a;
		if(a==0)break;
		b=1000-a;
		c=(b/500)+((b%500)/100)+(((b%500)%100)/50)+((((b%500)%100)%50)/10)+(((((b%500)%100)%50)%10)/5)+(((((b%500)%100)%50)%10)%5);
		cout<<c<<endl;
	}
	return 0;
}

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

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

C++: #include<stdio.h>
int main(){
	int i=0,a,b[6]={500,100,50,10,5,1},c=0;
	scanf("%d",&a);
	a=1000-a;
	while(a){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}

C++: #include<stdio.h>
int main(void)
{
	int gohyaku,hyaku,gozyu,zyu,go,ichi;
	int dai,otsuri,mai;
	scanf("%d",&dai);
	while(otsuri!=0){
		otsuri=1000-dai;
		gohyaku=0;
		hyaku=0;
		gozyu=0;
		zyu=0;
		go=0;
		ichi=0;
		while(otsuri!=0){
			while(otsuri>=500){
				otsuri=otsuri-500;
					gohyaku++;
			}
			while(otsuri>=100){
				otsuri=otsuri-100;
					hyaku++;
			}
			while(otsuri>=50){
				otsuri=otsuri-50;
					gozyu++;
			}
			while(otsuri>=10){
				otsuri=otsuri-10;
					zyu++;
			}
			while(otsuri>=5){
				otsuri=otsuri-5;
					go++;
			}
			while(otsuri>=1){
				otsuri=otsuri-1;
					ichi++;
			}
			mai=gohyaku+hyaku+gozyu+zyu+go+ichi;
			printf("%d\n",mai);
		}
	}
	return 0;
}

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

int memo[1111];

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  ans = min(solve(n-500)+1, min(solve(n-100)+1, min(solve(n-50)+1, min(solve(n-10)+1, min(solve(n-5)+1, solve(n-1)+1)))));
  
  return memo[n] = ans;
}

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

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	cin>>num1;
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
	return 0;
}