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<stdio.h>
int main(void)
{
	int n,i,a[6]={500,100,50,10,5,1},sum;
	
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		n=1000-n,sum=0;
		for(i=0;i<6;i++){
			sum+=n/a[i];
			n=n%a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        coin=0;
        cost=1000-cost;
        coin+=cost/500;
        cost%=500;
        coin+=cost/100;
        cost%=100;
        coin+=cost/50;
        cost%=50;
        coin+=cost/10;
        cost%=10;
        coin+=cost/5;
        cost%=5;
        coin+=cost;
        cout<<coin<<endl;
        cin>>cost;
    }
}

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

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

	while (cin >> m, m){
		int cnt = 0;
		int change = 1000 - m;

		for (int i = 0; i < 6; i++){
			cnt += change / coin[i];
			change %= coin[i]; // -= coin[i] * (change / coin[i]);
		}

		cout << cnt << endl;
	}

	return (0);
}

C++: #include <iostream>

using namespace std;

int main()
{
    int x;
    int ans;
    cin >> x;
    while(x!=0) {
        x=1000-x;
        ans=0;
        ans+=x/500;
        x=x%500;
        ans+=x/100;
        x=x%100;
        ans+=x/50;
        x=x%50;
        ans+=x/10;
        x=x%10;
        ans+=x/5;
        x=x%5;
        ans+=x;
        cout << ans;
        cin >> x;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int pay,num;
	while (cin >> pay)

	{
		num = 0;
		if (!pay) break;

		pay = 1000 - pay;
		if (pay / 500 == 1){
			pay -= 500;
			num++;
		}
		for (;;){
			if (pay / 100 >= 1){
				pay -= 100;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 50 >= 1){
				pay -= 50;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay / 10 >= 1){
				pay -= 10;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 5){
				pay -= 5;
				num++;
			}
			else break;
		}
		for (;;){
			if (pay >= 1){
				pay -= 1;
				num++;
			}
			else break;
		}
		cout << num << endl;
	}
}

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

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

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

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

int  main(){
  int n;
  while(1){
  int count=0;
  cin >> n;
  if(n==0)break;
  int total = 1000-n;
  if(total >= 500){
  count+=total/500;
  total%=500;
  }

  if(total >= 100){
  count+=total/100;
  total%=100;
  }
  
  if(total >= 50){
  count+=total/50;
  total%=50;
  }

  if(total >= 10){
  count+=total/10;
  total%=10;
  }

  if(total >=  5){
  count+=total/5;
  total%=5;
  }

  if(total >=  1)
  count+=total/1;

  cout << count << endl;

  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

	if(n>=500){
		m = n/500;
		n = n%500;
	}
	if(n>=100){
		m = m+n/100;
		n = n%100;
	}
	if(n>=50){
		m = m+n/50;
		n = n%50;
	}
	if(n>=10){
		m = m+n/10;
		n = n%10;
	}
	if(n>=5){
		m = m+n/5;
		n = n%5;
	}
	if(n>=1){
		m = m+n/1;
	}

	cout << m << endl;

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int mo,fite,hund,fiten,ten,go,one;
    cin>>mo;
    mo=1000-mo;
    fite=mo/500;
    hund=mo%500/100;
    fiten=mo%500%100/50;
    ten=mo%500%100%50/10;
    go=mo%500%100%50%10/5;
    one=mo%500%100%50%10%5;
    //cout<<fite<<" "<<hund<<" "<<fiten<<" "<<ten<<" "<<go<<" "<<one<<"\n";
    cout<<fite+hund+fiten+ten+go+one<<"\n";
}

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		int c=1000-n,ans=0;
		while(c>=500) c-=500,++ans;
		while(c>=100) c-=100,++ans;
		while(c>=50) c-=50,++ans;
		while(c>=10) c-=10,++ans;
		while(c>=5) c-=5,++ans;
		while(c>=1) c-=1,++ans;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int n;
  int sm;
  while(cin>>n&&n){
    n=1000-n;
    sm=0;
    while(n>=500){
      n-=500;
      sm++;
    }
    while(n>=100){
      n-=100;
      sm++;
    }
    while(n>=50){
      n-=50;
      sm++;
    }
    while(n>=10){
      n-=10;
      sm++;
    }
    while(n>=5){
      n-=5;
      sm++;
    }
    while(n){
      n--;
      sm++;
    }
    cout<<sm<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int p;
int main(){
	while(true){
		cin>>p;if(p==0)break;
		p=1000-p;
		int a1=p/500;p-=500*a1;
		int a2=p/100;p-=100*a2;
		int a3=p/50;p-=50*a3;
		int a4=p/10;p-=10*a4;
		int a5=p/5;p-=5*a5;
		int a6=p/1;p-=1*a6;
		cout<<a1+a2+a3+a4+a5+a6<<endl;
	}
	return 0;
}

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

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

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

int main() {
	int sum, sum2, num500, num100, num50, num10, num5, num1, numcoin;
	
	while (1) {
		cin >> sum;
		if (sum == 0) break;
		num500 = num100 = num50 = num10 = num5 = num1 = 0;
		
		sum2 = 1000 - sum;
		if (sum2 >= 500) {
			num500++;
			sum2 -= 500;
		}
		if(sum2 >= 100) {
			num100 += sum2 / 100;
			sum2 %= 100;
		}
		if (sum2 >= 50) {
			num50++;
			sum2 -= 50;
		}
		if (sum2 >= 10) {
			num10 += sum2 / 10;
			sum2 %= 10;
		}
		if (sum2 >= 5) {
			num5++;
			sum2 -= 5;
		}
		num1 = sum2;
		
		numcoin = num500 + num100 + num50 + num10 + num5 + num1;
		cout << numcoin <<endl;
	}
	return 0;
}

C++: #include <iostream>

using std::cout;
using std::cin;

int main(int argc, const char * argv[]) {
    std::ios::sync_with_stdio(false);
    
    int en;
    int ans;
    int set[]={500,100,50,10,5,1};
    
    
    
    
    while(cin>>en&&en!=0)
    {
    en=1000-en;
        
        for (int i=0;i<sizeof(set)/sizeof(set[0]); ++i)
        {
            while(true)
            {
                if(set[i]<=en)
                {
                    en-=set[i];
                    ++ans;
                }
                else
                {
                    break;
                }
            }
        }
        cout<< ans <<"\n";
        ans=0;
    }

    
    return 0;
}

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