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>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	while(cin>>a){
		if(a==0)break;
		s=0;
		a=1000-a;
		if(a>499){
			a=a-500;
			s=s+1;
		}
		for(i=0;i<4;i++){
			if(a>99){
				a=a-100;
				s=s+1;
			}
		}
		if(a>49){
			a=a-50;
			s=s+1;
		}
		for(i=0;i<4;i++){
			if(a>9){
				a=a-10;
				s=s+1;
			}
		}
		if(a>4){
			a=a-5;
			s++;
		}
		s=s+a;
		cout<<s<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int m;
int cal(int a)
{
	int k=m/a;
	m-=a*k;
	return k;
}
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		m=1000-n;
		int ans=0;
		ans+=cal(500);
		ans+=cal(100);
		ans+=cal(50);
		ans+=cal(10);
		ans+=cal(5);
		ans+=cal(1);
		cout << ans << endl;
	}
	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>
#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;

	cin>>num1;
	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 <cstdio>
using namespace std;
int main()
{while(1){
 int a;
 scanf("%d",&a);
if(a==0) return 0;
 a=1000-a;
 printf("%d\n",a/500a+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);}
}

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

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

C++: #include<iostream>
#include<string>
#include<vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	int temp = 0;
	int cost_input[10];
	int cost_return = 0;
	int num = 0;
	int j = 0;

	for (int i = 0; i < 10; ++i) {
		CI temp;
		if (temp == 0) {
			j = i;
			break;
		}
		cost_input[i] = temp;

		cost_return = 1000 - cost_input[i];
		num = 0;

		if (cost_return < 5) {
			num = cost_return;
			break;
		}
		else {
			if (cost_return < 10) {
				num = 1 + cost_return - 5;
			}
		}


		if (cost_return >= 500) {
			++num;
			cost_return -= 500;
		}
		while (1) {
			if (cost_return >= 100) {
				++num;
				cost_return -= 100;
			}
			if (cost_return < 100)break;
		}
		if (cost_return >= 50) {
			++num;
			cost_return -= 50;
		}
		while (1) {
			if (cost_return >= 10) {
				++num;
				cost_return -= 10;
				if (cost_return < 10)break;
			}
		}

		if (cost_return >= 5) {
			++num;
			cost_return -= 5;
		}
		while (1) {
			if (cost_return >= 1) {
				++num;
				cost_return -= 1;
			}
			if (cost_return < 1)break;
		}
	
	}
	

	for (int i = 0; i < j;++i) {
		CO num E
	}
}

C++: #include<iostream>

using namespace std;

int main(void) {
	int now, count;

	while(true) {
		cin >> now;
		if(now == 0) { break; }
		count = 0;
		now = 1000 - now;
		while(now > 0) {
			if(now >= 500) {
				now -= 500;
				count++;
			} else if(now >= 100) {
				now -= 100;
				count++;
			} else if(now >= 50) {
				now -= 50;
				count++;
			} else if(now >= 10) {
				now -= 10;
				count++;
			} else if(now >= 5) {
				now -= 5;
				count++;
			} else {
				now -= 1;
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int ans, n, rest, itr;
    const int coin[] = {500, 100, 50, 10, 5, 1};
    while(true){
        cin >> n;
        if(n == 0){
            break;
        }
        else {
            itr = 0;
            ans = 0;
            rest = 1000 - n;
            while(rest > 0){
                if(itr >= 6){
                    break;
                }
                else if(rest - coin[itr] >= 0){
                    ans++;
                    rest -= coin[itr];
                }
                else {
                    itr++;
                }
            }
            cout << ans << endl;
        }
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 3000
using namespace std;

int C[6]={1,5,10,50,100,500};
int T[MAX+1];
void douteki();

int main(){
  int n;
 

  while(cin >> n){
    douteki();
    cout << T[1000-n] << endl;
  }



}

void douteki(){
  for(int j=0;j<=MAX;j++)T[j]=10000;
  T[0]=0;
  for(int i=0;i<6;i++){
    for(int j=C[i];j<=MAX;j++){
      T[j]=min(T[j],T[j-C[i]]+1);
    }
  }

}

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()
{
  while(cin >>N,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>
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) 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;
		}
	}
	}
	
	cout << i << "\n";		

	return 0;
}