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<cstdio>
using namespace std;
int main(){
  int n,ans,sum;
  scanf("%d",&n);
  while(n != 0){
    ans = 0;
    sum = 1000-n;
    
    while(sum >= 500){
      sum -= 500;
      ans++;
    }
    while(sum >= 100){
      sum -= 100;
      ans++;
    }
    while(sum >= 50){
      sum -= 50;
      ans++;
    }
    while(sum >= 10){
      sum -= 10;
      ans++;
    }
    while(sum >= 5){
      sum-=5;
      ans++;
    }
    while(sum != 0){
      sum--;
      ans++;
    }
    cout << ans << endl;
    scanf("%d",&n);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
int v[6] = {500, 100, 50, 10, 5, 1};
int greed(int n)
{
    int count = 0;
    rep(i, 6)
    {
        int cc = n / v[i];
        n -= cc * v[i];
        count += cc;
    }
    return count;
}
int main()
{
    int n;
    while (scanf("%d%*c", &n))
    {
        if (n == 0)
        {
            break;
        }
        int ans = greed(1000-n);
        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)%10+(a/5)%2+a%5);
}

C++: #include<iostream>
int c[]={500,100,50,10,5,1};
int main(){int n,r,i;while(1){std::cin>>n;if(!n)break;n=1000-n,r=0;for(i=0;i<6;i++)r+=n/c[i],n%=c[i];std::cout<<r<<"\n";}}

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

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

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

	for(int price; cin >> price, price;) {
		int change = 1000 - price;
		int ans = 0;
		
		for(int i = 0; i < 6; ++i) {
			while(change >= coins[i]) {
				change -= coins[i];
				++ans;
			}
		}
		
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include<stdio.h>

int main(){
	int kane,a,b;
	while(0<=scanf("%d",&kane)){
		if(kane==0) break;
		a=0;
		kane=1000-kane;
		while(kane>=500){
			kane-=500;
			++a;
		}
		while(kane>=100){
			kane-=100;
			++a;
		}
		while(kane>=50){
			kane-=50;
			++a;
		}
		while(kane>=10){
			kane-=10;
			++a;
		}
		while(kane>=5){
			kane-=5;
			++a;
		}
		while(kane>=1){
			kane-=1;
			++a;
		}
		printf("%d\n",a);
	}
	return 0;
}

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

int main(){
while(true){
  int iwakurasisetudan;
  int b;
  int c;
  cin>>iwakurasisetudan;
if(iwakurasisetudan==0){break;
}else{  c=1000-iwakurasisetudan;
  b=c/500;
  c=c%500;
  b=b+c/100;
  c=c%100;
  b=b+c/50;
  c=c%50;
  b=b+c/10;
  c=c%10;
  b=b+c/5;
  c=c%5;
  b=b+c;
  cout<<b<<endl;
}}}

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

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

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1){
int b=a/1;
i+=b;
a-=1*b;
}
}
return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    int ans=0;
    while(cin>>n,n){
        int hoge=1000-n;
        int a=hoge/500;
        hoge-=a*500;
        ans+=a;
        a=hoge/100;
        hoge-=a*100;
        ans+=a;
        a=hoge/50;
        hoge-=a*50;
        ans+=a;
        a=hoge/10;
        hoge-=a*10;
        ans+=a;
        a=hoge/5;
        ans+=a;
        hoge-=a*5;
        cout<<ans+hoge<<endl;
        
    }
}

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

C++: #include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n[5], count=0, coin[] = { 500,100,50,10,5 };

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

	for (int j=0;j<5;j++) {
	   int m = s / coin[j];
	   count += m;
	   s -= m * coin[j];
	}

	count += s;
	cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int coin[6] = {500, 100, 50, 10, 5, 1};
	int cost;
	
	
	while (cin >> cost){
		int count = 0;
		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;

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

int main() {

	int change, coins;

	while (cin >> change, change) {
		change = 1000 - change;

		coins = 0;
		for (int i = 0; i < 6; ++i) {
			if (change >= coin[i]) {
				coins += change / coin[i];
				change -= coins * coin[i];
				if (!change)
					break;
			}
		}
		cout << coins << endl;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main() {
	int a;
	cin >> a;
	a = 1000 - a;
	int counter = 0;
	if (a >= 500) {
		counter += a/500;
		a %= 500;
	}
	if (a >= 100) {
		counter += a/100;
		a %= 100;
	}
	if (a >= 50) {
		counter += a/50;
		a %= 50;
	}
	if (a >= 10) {
		counter += a/10;
		a %= 10;
	}
	if (a >= 5) {
		counter += a/5;
		a %= 5;
	}
	if (a >= 1) {
		counter += a;
	}
	cout << counter << endl;
	return 0;
}