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>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        n=1000-n;
        int count=0;
        if(n>=500){
            count++;
            n -= 500;
        //    cout<<"500"<<endl;
        }
        if(n>=100){
            while(n>=100){
                count++;
                n -= 100;
          //      cout<<"100"<<endl;
            }
        }
        if(n>=50){
            count++;
            n -= 50;
         //   cout<<"50"<<endl;
        }
        if(n>10){
            while(n>=10){
                count++;
                n -= 10;
             //   cout<<"10"<<endl;
            }
        }
        if(n>=5){
            count++;
            n -= 5;
          //  cout<<"5"<<endl;
        }
        count += n;
        cout<<count<<endl;
    }
}

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

int main() {
	int all, rem, count = 0, tmp;
	while (1) {
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
	}
	return 0;
}

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

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

int main(void){
	int mon, cnt = 0;
	cin >> mon;
	mon = 1000 - mon;
	for(int i = 0; i < 6; i++){
		if(mon == 0)	break;
		cnt += mon / change[i];
		mon -= change[i] * (mon / change[i]);
	}
	cout << cnt << endl;
  return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int price;
	int oturi;
	int count = 0;
	cin >> price;

	oturi = 1000 - price;

	for (; price > 0;)
	{
		if (price >= 500)
		{
			count++;
			price -= 500;
		}
		else if (price >= 100)
		{
			count++;
			price -= 100;
		}
		else if (price >= 50)
		{
			count++;
			price -= 50;
		}
		else if (price >= 10)
		{
			count++;
			price -= 10;
		}
		else if (price >= 5)
		{
			count++;
			price -= 5;
		}
		else if (price >= 1)
		{
			count++;
			price -= 1;
		}
	}

	cout << count << endl;

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
using namespace std;
 
 
int main(){
    int coin[6]={1,5,10,50,100,500},in,ans;
     
 
 while(1){
    ans=0;
    scanf("%d",&in);
     
    if(in==0)
      break;
 
    in=1000-in;
     
    for(int i=5;i>=0;i--){
        ans+=in/coin[i];
        in%=coin[i];
    }
     
    printf("%d\n",ans);
     
  }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	while(1)
	{
		cin>>k;
		if(k==0)
			break;
		n=k/500+k%500/100+k%500%100/50+k%500%100%50/10+k%500%100%50%10/5+k%500%100%50%10%5;
		cout<<n<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
	int n;
	
	while(cin >> n && n){
		int v = 1000 - n;
		int ret = 0;
		
		ret += v / 500;
		v -= (v / 500) * 500;
		
		ret += v / 100;
		v -= (v / 100) * 100;
		
		ret += v / 50;
		v -= (v / 50) * 50;
		
		ret += v / 10;
		v -= (v / 10) * 10;
		
		ret += v / 5;
		v -= (v / 5) * 5;
		
		ret += v;
		cout << ret << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,x,p[6]={500,100,50,10,5,1},ans=0;
	while(1){
		ans=0;
		cin>>a;
		if(a==0)
		break;
		x=1000-a;
		for(int i=0;i<6;i++){
			while(1){
				if(x>=p[i]){
				x-=p[i];
				ans++;
				}else
				break;
			}
		}
		cout<<ans<<endl;
	}
return 0;
}

C++: #include <cstdio>
using namespace std;
int main()
{
 int a;
 scanf("%d",&a);
 a=1000-a;
 printf("%d\n",((a/500))+((a/100)%5)+((a/50)%2)+((a/10)%5)+((a/5)%2)+(a%5));
}

C++: #include <iostream>
using namespace std;
int main(void){
    int i=0,n,x,c;
    while(i<5){
        cin >> x;
        if(x==0) break;
        c=0;
        n=1000-x;
        if(n>=500){
            c++;
            n-=500;
        }
        while(n>=100){
            c++;
            n-=100;
        }
        if(n>=50){
            c++;
            n-=50;
        }                
        while(n>=10){
            c++;
            n-=10;
        }
        if(n>=5){
            c++;
            n-=5;
        }
        while(n>0){
            c++;
            n-=1;
        }
        i++;
        cout<<c<<endl;
    }
    
}

C++: #include<stdio.h>
int main(void)
{
	int s,ss,sss;
	while(1){
		scanf("%d",&s);
		if(s==0) break;
		ss=1000-s;
		sss=ss/500;

		ss=ss%500;
		sss+=ss/100;

		ss=ss%100;
		sss+=ss/50;

		ss=ss%50;
		sss+=ss/10;

		ss=ss%10;
		sss+=ss/5;

		ss=ss%5;
		sss+=ss/1;

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

C++: #include<iostream>

using namespace std;

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

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[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << endl;
	cout << onum[1] << endl;
	cout << onum[2] << endl;
	cout << onum[3] << endl;
	cout << onum[4] << endl;
	return 0;
}

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

int main()
{

	while(true){

		int t;
		int count = 0;

		cin >> t;
		if(t==0)
			break;

		t = 1000-t;

		count += t/500;
		t = t-500*(t/500);

		count += t/100;
		t = t-100*(t/100);

		count += t/50;
		t = t-50*(t/50);

		count += t/10;
		t = t-10*(t/10);

		count += t/5;
		t = t-5*(t/5);

		count += t;

		cout << count << endl;
	}
	return 0;
}