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<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,c[6]={500,100,50,10,5,1},ans;
	while(true){
		cin>>n;
		if(!n)break;
		n=1000-n,ans=0;
		for(int i=0;i<6;i++)ans+=n/c[i],n%=c[i];
		cout<<ans<<endl;
	}
	return 0;
}

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;
//		printf("500sss=%d\n",sss);
		ss=ss%500;
		sss+=ss/100;
//				printf("100sss=%d\n",sss);
		ss=ss%100;
		sss+=ss/50;
//				printf("50sss=%d\n",sss);
		ss=ss%50;
		sss+=ss/10;
//				printf("10sss=%d\n",sss);
		ss=ss%10;
		sss+=ss/5;
//				printf("5sss=%d\n",sss);
		ss=ss%5;
		sss+=ss/1;
//				printf("1sss=%d\n",sss);
//		sss++;
	printf("%d\n",sss);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
	solve();
	return(0);
}

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

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <stdio.h>
using namespace std;

int i, ans;



int main() {


	while (true) {
		cin >> i;
		if (i == 0) break;
		i = 1000 - i;
		ans += i / 500;
		i %= 500;
		ans += i / 100;
		i %= 100;
		ans += i / 50;
		i %= 50;
		ans += i / 10;
		i %= 10;
		ans += i / 5;
		i %= 5;
		ans += i;
		cout << ans << endl;
		ans = 0;
	}


	return 0;
}

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