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

C++: #include<iostream>
using namespace std;
int main(){
	int coin[6] = {500,100,50,10,5,1};
	int money;
	while(cin >> money){
		int sum=0;
		money=1000-money;
		for(int i=0; i<6; i++){
			int count=0;
			while(money >= coin[i]){
				count++;
				money-=coin[i];
			}
			sum+=count;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: // 2011/09/09 Tazoe

#include <iostream>
using namespace std;

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

		n = 1000-n;

		int sum = 0;

		sum += n/500;
		n %= 500;

		sum += n/100;
		n %= 100;

		sum += n/50;
		n %= 50;

		sum += n/10;
		n %= 10;

		sum += n/5;
		n %= 5;

		sum += n;

		cout << sum << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int main() {
	int n;
	while (cin >> n && n != 0) {

		n = 1000 - n;
		int cnt = 0;
		int coin[] = { 500, 100, 50, 10, 5 };
		for (int i = 0; i < 5; ++i) {
			if (n >= coin[i]) {
				cnt += n / coin[i];
				n = n % coin[i];
			}
		}
		cnt += n;

		cout << cnt << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(!n) break;

        n = 1000-n;
        int cnt = 0;
        cnt += n/500;
        n %= 500;
        cnt += n/100;
        n %= 100;
        cnt += n/50;
        n %= 50;
        cnt += n/10;
        n %= 10;
        cnt += n/5;
        n %= 5;
        cnt += n;
        cout << cnt << endl;
    }
    return 0;
}

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

C++: #include<unordered_map>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<chrono>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n!=0){
		n=1000-n;
		int sum=0;
		int c[6]={500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			while(n>=c[i]){
				n-=c[i];
				sum++;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>

using namespace std;

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

	return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
m=1000-m;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans;

}

}

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	while(cin>>a){
		if(a==0)break;
		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<iostream>
using namespace std;

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

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

int main(){
	int n, cnt=0;
	cin >> n;
	n = 1000 - n;
	while(n >= 500){
		n -= 500;
		cnt++;
	}
	while(n >= 100){
		n -= 100;
		cnt++;
	}
	while(n >= 50){
		n -= 50;
		cnt++;
	}
	while(n >= 10){
		n -= 10;
		cnt++;
	}
	while(n >= 5){
		n -= 5;
		cnt++;
	}
	while(n >= 1){
		n -= 1;
		cnt++;
	}

	cout << cnt << endl;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
    while(cin>>n && n){
    int cost = 1000 - n;
    int cnt=0;
    cnt += cost/500;
    cost = cost%500;
    cnt += cost/100;
    cost = cost%100;
    cnt += cost/50;
    cost = cost%50;
    cnt += cost/10;
    cost = cost%10;
    cnt += cost/5;
    cost = cost%5;
    cnt += cost/1;
    cost = cost%1;
    cout<<cnt<<endl;
  }
}

C++: #include <stdio.h>
using namespace std;

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
}

C++: #include <iostream>

int main() {
	int a,coin = 0;
	std::cin >> a;
	a = 1000 - a;

	coin += a / 500;
	a = a - ((a / 500) * 500);
	coin += a / 100;
	a = a - ((a / 100) * 100);
	coin += a / 50;
	a = a - ((a / 50) * 50);
	coin += a / 10;
	a = a - ((a / 10) * 10);
	coin += a / 5;
	a = a - ((a / 5) * 5);
	coin += a / 1;
	a = a - ((a / 1) * 1);

	std::cout << coin;




}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	int d;
	int e;
	int f;
	int g;
	int h;
	int i;
	int j;
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		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 <iostream>
using namespace std;
int count(int x, int c) {
    if(x >= 500) {
        return count(x-500, c+1);
    }
    if(x >= 100) {
        return count(x-100, c+1);
    }
    if(x >= 50) {
        return count(x-50, c+1);
    }
    if(x >= 10) {
        return count(x-10, c+1);
    }
    if(x >= 5) {
        return count(x-5, c+1);
    }
    if(x == 0) {
        return c;
    }
    else {
        return count(x-1, c+1);
    }
}

int main(void){
    int x;
    while(true) {
        cin >> x;
        if(x == 0) {
            break;
        }
        cout << count(1000 - x, 0) << endl;
    }
}