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 a=1;
	int b;
	int c;
	
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		while (b!=0)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			else if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			else if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			else if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			else if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			else if (b >= 1)
			{
				b = b - 1;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

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

using pii = pair<int, int>;

constexpr int INF = 1e9;

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

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout << b/500+c/100+d/50+e/10+f/5+g << endl;
	
	return 0;
}

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

int main(){
	int n;
	int coin[6]={500,100,50,10,5,1};
	while(cin>>n,n){
		int ans=0;
		n = 1000-n;
		for(int i=0;i<6;i++){
			ans += n/coin[i];
			n %= coin[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	for(int i=0;i<150;i++){
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	}
	return 0;
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<PP, int> PPP;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};





int main(){
	int a, b;
	while(cin >> a){
		b = 1000 - b;
		int ret = 0;
		while(b != 0){
			if(b >= 500){
				ret++;
				b -= 500;
			}else if(b >= 100){
				ret += b/100;
				b %= 100;
			}else if(b >= 10){
				ret += b/10;
				b %= 10;
			}else if(b >= 5){
				ret += b/5;
				b %= 5;
			}else{
				ret += b;
				b = 0;
			}
		}
		cout << ret << endl;
	}

	return 0;
}

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

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

int main() {
  while (true) {
    int t; cin >> t;
    if (t == 0) break;

    int x = 1000 - t;
    int cnt = 0;
    while (x > 0) {
      if (x / 500 > 0) {
        cnt += x / 500;
        x %= 500;
      } else if (x / 100 > 0) {
        cnt += x / 100;
        x %= 100;
      } else if (x / 50 > 0) {
        cnt += x / 50;
        x %= 50;
      } else if (x / 10 > 0) {
        cnt += x / 10;
        x %= 10;
      } else if (x / 5 > 0) {
        cnt += x / 5;
        x %= 5;
      } else if (x / 1 > 0) {
        cnt += x / 1;
        x %= 1;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "endl";
 
    
    }
    return 0;

}

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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int s, o;
	while(cin >> s, s) {
		s = 1000 - s;
		o = 0;
		while(s >= 500) {
			s -= 500;
			o++;
		}
		while(s >= 100){
			s -= 100;
			o++;
		}
		while(s >= 50){
			s -= 50;
			o++;
		}
		while(s >= 10){
			s -= 10;
			o++;
		}
		while(s >= 5){
			s -= 5;
			o++;
		}
		o += s;
		cout << o << endl;
	}

	return 0;

}

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

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

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;



	while (true) {
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,o,s,m;
	
	scanf("%d",&m);
	
	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);
	
	return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;
    }
   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
 }
   
  return 0;
}