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 <bits/stdc++.h>

int main() {

    int N, sum, idx;
    int b[] = {500, 100, 50, 10, 5, 1};
    for (; ;) {
        std::scanf("%d", &N);
        if (N == 0) break;
        N = 1000 - N;
        sum = idx = 0;
        while (N > 0) {
            sum += int(N/b[idx]);
            N %= b[idx];
            idx++;
        }
        std::printf("%d\n", sum);
    }
    return  0;
}

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

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

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    n = 1000 - n;

    int a = n / 500;
    n %= 500;

    int b = n / 100;
    n %= 100;

    int c = n / 50;
    n %= 50;

    int d = n / 10;
    n %= 10;

    int e = n / 5;
    int f = n % 5;

    int ans = a + b + c + d + e + f;
    cout << ans << endl;
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;

//change

int main(){
	int n;
	int coin[6] = {500, 100, 50, 10, 5, 1};

	while(cin >> n){
		if(!n) return 0;

		int ans=0;
		n = 1000 - n;

		for(int i=0 ; i<6 ; i++){
			int temp = n / coin[i];
			ans += temp;
			n -= temp*coin[i];
		}

		cout << ans << endl;


	}
	return 0;
}

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

int a,sum,ans,dx[6]={500,100,50,10,5,1};

int main (){
    cin >> a;
    a=1000-a;

    for(int i=0;i<6;i++){
    ans=a/dx[i];
    sum=sum+ans;
    a=a%dx[i];
    ans=0;
    }

    cout << sum << endl;
    return 0;
}

C++: #include <cstdio>

int main() {
	int num,n,i,a,b;
	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\n",i);
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, t, c[6] = {500, 100, 50, 10, 5, 1}, i, s, m, u;
	while (cin >> n && n)
	{
		t = 1000 - n;
		m = 0;
		while (t)
		{
			if (t >= 500)		s = 0;
			else if (t >= 100)	s = 1;
			else if (t >= 50)	s = 2;
			else if (t >= 10)	s = 3;
			else if (t >= 5)	s = 4;
			else				s = 5;
			for (i = s; i < 6; i++)
			{
				u = t / c[i];
				m += u;
				t -= c[i] * u;
			}
		}
		cout << m << endl;
	}
}

C++: #include <iostream>

int main(){
    while(true){
        int n;
        std::cin >> n;
        
        if(n == 0) {
            break;
        }
        
        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 / 1;
        n %= 1;
    
        std::cout << count << std::endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int money,change,num=0;
        cin>>money;
        if(money==0){
            break;
        }
        change=1000-money;
        num+=(change/500);
        change%=500;
        num+=(change/100);
        change%=100;
        num+=(change/50);
        change%=50;
        num+=(change/10);
        change%=10;
        num+=(change/5);
        change%=5;
        num+=change;
        cout<<num<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_std(false);
    int n[5], count=0;

    for (int i=0; i<5; i++) cin >> n[i];

    for (int i=0;i<5;i++) {
	if(n[i] == 0) break;

	int s=1000 - n[i];

	int j = (s - s % 500)/500;
        count += j;
	s -= j*500;
        j = (s - s % 100)/100;
        count += j;
	s -= j*100;
        j = (s - s % 100)/100;
        count += j;
	s -= j*50;
        j = (s - s % 50)/50;
        count += j;
	s -= j*10;
        j = (s - s % 10)/10;
        count += j;
	s -= j*10;
        j = (s - s % 5)/5;
        count += j;
	s -= j*5;
        count += s;

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

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N;
	while(N){
	    N = 1000 - N;
	if (N >= 500)N -= 400;
	int ans = N / 100;
	N %= 100;
	if (N >= 50)N -= 40;
	ans += N / 10;
	N %= 10;
	if (N >= 5)N -= 4;
	ans += N;
	cout << ans << endl;
	cin>>N;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

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

int main() {
	int N;
	
	while (cin >> N, N) {
		int A = 1000 - N, ans = 0;
		
		for_(i,0,6) {
			while (A >= coin[i]) {
				A -= coin[i];
				++ans;
			}
		}
		
		cout << ans << endl;
	}
}

C++: #include <iostream>

using namespace std;

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

C++: #include<iostream>
using namespace std;
int main(){
  int turi;
  int hara;
  int count;
  while(1){
    count=0;
    cin>>hara;
    if(hara==0) break;
    turi=1000-hara;
    while(turi!=0){
      if(turi>=500){
	turi=turi-500;
	count++;
      }
      else if(turi>=100){
	turi=turi-100;
	count++;
      }
      else if(turi>=50){
	turi=turi-50;
	count++;
      }

      else if(turi>=10){
	turi=turi-10;
	count++;
      }
      
      else if(turi>=1){
	turi=turi-1;
	count++;
      }
    }
    cout<<count<<endl;
  }
}

C++: #include<iostream>

using namespace std;

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

	oturi = 1000 - price;

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

	cout << count << endl;

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int ans = 0;
  ans += (1000 - t)/500;
  ans += ((1000 - t)/100) - 5*((1000 - t)/500);
  ans += ((1000 - t)/10)-10*((1000 - t)/100);
  cout << ans << endl;
  return 0;
}