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 <bits/stdc++.h>
using namespace std;

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1)
int b=a/1;
i+=a;
}
return 0;
}

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

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value/500; value%=500;
coins += value/100; value%=100;
coins += value/50; value%=50;
coins += value/10; value%=10;
coins += value/5; value%=5;
coins += value;
cout << coins;
}
return 0;
}

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

int main() 
{ 
 int buy,oturi,kozeni,a,b,c,d,e,f; 
 while(1){
  cin>>buy;
  if(buy==0)
   break;
  else{
   oturi=1000-buy;
   a=oturi/500;
   if(a)b=(oturi-500)/100;
     else b=oturi/100;
   c=oturi%100/50;
   if(c)d=(oturi%100-50)/10;
     else d=oturi%100/10;
   e=oturi%10/5;
   if(e)f=oturi%10-5;
      else f=oturi%10;   

   kozeni=a+b+c+d+e+f;
   cout<<kozeni<<"\n";
  }
 }
 return 0; 
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int money = 1000;
	int pay, change, i;

	cin >> pay;
	change = money - pay;

	while(1){
	if(change == 0 || change == 1000) break;
	else if(change < 0 || 1000 < change) break;
	while(1){
		if(change - 500 >= 0){
			i += 1;
			change -= 500;
			break;
		}
		else if(change - 100 >= 0){
			i += 1;
			change -= 100;
			break;
		}
		else if(change - 50 >= 0){
                        i += 1;
                        change -= 50;
                        break;
                }
		else if(change - 10 >= 0){
                        i += 1;
                        change -= 10;
                        break;
                }
		else if(change - 5 >= 0){
                        i += 1;
                        change -= 5;
                        break;
                }
		else{
			i += 1;
			change -= 1;
			break;
		}
	}
	}
	
	if(pay == 0 ) return 0;
        else if(pay < 0 || 1000 < pay) return 0;
	else cout << i << "\n";

	
	return 0;
}

C++: #include <cstdio>

int main() {
	int num,n,i,a,b;
	a=0,b=0,i=0;
	scanf("%d",&num);
	n=1000-num;

	if (n>500) {
		i++;
		n=(n-500);
	}
	if (n>100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>50){
		i++;
		n=(n-50);
	}
	if (n>10){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>5){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d",i);
	return 0;
}

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

int main(){
    const int m[6] = {500,100,50,10,5,1};
    int price;
    
    while(true){
        cin >> price;
        if(!price) break;
        
        int change = 1000 - price,cnt = 0;
        for(int i = 0 ; i < 7 ;){
            if(change >= m[i]){
                change -= m[i];
                cnt++;
            }
            else i++;
            
            if(!change) break;
        }
        cout << cnt << endl;
    }
    
    return 0;
}

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

int minChange(int money)
{
	int coin[6]={500, 100, 50, 10, 5, 1};
	int n=0;
	while(money > 0)
	{
		for(int i=0; i<6; i++)
		{
			if(money >= coin[i])
			{
				money -= coin[i];
				n++;
				break;
			}
		}
	}
	return n;
}

int main(void)
{
	int money;
	while(1)
	{
		cin >> money;
		if(money == 0)return 0;

		cout << minChange(1000-money) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>

using namespace std;

#define print(a) printf("%d\n", a)

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

#define MAX(a,b) ((a)>(b)?(a):(b))


int main(){
	int co, mod, ch;
	
	while (cin >> co , co != 0){
		ch = 0;
		
		mod = 1000 - co;
	
		ch += mod/500;
		mod = mod%500;
	
		ch += mod/100;
		mod = mod%100;
	
		ch += mod/50;
		mod = mod%50;
	
		ch += mod/10;
		mod = mod%10;
	
		ch += mod/5;
		mod = mod%5;
	
		ch += mod;
	
		cout << ch << endl;
	}
	
	return 0;
}

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

int main(){
  int m,sum = 0;
  cin >> m;
  m = 1000 - m;
  sum += m / 500;
  m %= 500;
  sum += m / 100;
  m %= 100;
  sum += m / 50;
  m %= 50;
  sum += m / 10;
  m %= 10;
  sum += m / 5;
  m %= 5;
  cout << sum + m << endl;
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
while(true){
	int n;
	cin >> n;
if(n==0)  break;
	int m = 1000-n;

	int sum = 0;

	sum += m/500;
	m %= 500;

	sum += m/100;
	m %= 100;

	sum += m/50;
	m %= 50;

	sum += m/10;
	m %= 10;

	sum += m/5;
	m %= 5;

	sum += m;

	cout << sum << '\n';
}
	return 0;
}

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


int main(){
    while(1)
    {
        int i;
        cin>>i;
        if(i==0)break;
        int remain = 1000-i;
        int count = 0;
        while(remain!=0)
        {
            if(remain>=500)
            {
                count++;
                remain -= 500;
            }
            else if(remain>=100)
            {
                count++;
                remain -= 100;
            }
            else if(remain>=50)
            {
                count++;
                remain -= 50;
            }
            else if(remain>=10)
            {
                count++;
                remain -= 10;
            }
            else if(remain>=5)
            {
                count++;
                remain -= 5;
            }
            else if(remain>=1)
            {
                count++;
                remain -= 1;
            }
        }
        cout<<count<<endl;
    }
    
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

int main()
{
  cin >>N;
  N =1000-N;
  int ans = 0;
  int c[6] ={500,100,50,10,5,1};
  for(int i =0;i < 6;i++){
   while(N/c[i]){
      ans++;
      N -=c[i];
    }
  }
  cout <<ans<<endl;
  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;
	*/

	//おつり
	while(true){
		int N;
		if(N == 0) break;
		
		int nedan;
		cin >> nedan;
		int oturi = 1000-nedan;
		int onum= 0;
		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;
}