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

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>

using namespace std;

int main(int argc, char **argv){
	int n;
	int kane[] = { 500, 100, 50, 10, 5, 1 };
	int count;
	while (cin >> n && n != 0) {
		count = 0;
		n = 1000 - n;
		for (int i = 0; i < 6; i++) {
			count += (n / kane[i]);
			n %= kane[i];
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;
int n;
int coin[6] = {500, 100, 50, 10, 5, 1};

int main(int argc, char const* argv[])
{
	while(true){
			cin >> n;
			if(n == 0)break;
			n = 1000 - n;
			int res = 0;
			for(int i = 0; i < 6; i++){
					res += n / coin[i];
					n = n % coin[i];
			}
			cout << res << endl;
	}
	return 0;
}

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

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

int main(){
	int x, y = 0;
	scanf("%d", &x);
	x = 1000 - x;
	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>
#include<string>

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/
	
	//おつり
	int onum;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum++;
			oturi -= 1;
		}
		 cout << onum << endl;
	}
   
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt;
cin>>price;
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=500;
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

int yen;
int ans=0;

while(cin>>yen){
if(yen==0) break;
ans=yen%5;
yen/=5;
ans+=yen%2;
yen/=2;
ans+=yen%5;
yen/=5;
ans+=yen%2;
yen/=2;
ans+=yen%5;
ans+=yen/5;
cout<<ans<<endl;
}
}

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!=0){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d",c);
}