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() {
  for (int i = 0; i < 5; i++) {
    int n; cin >> n;
    
    if (n == 0) break;
    int ch = 1000 - n;
    
    int ans = 0;
    if (ch > 0 && ch >= 500) {
      ans += ch / 500;
      ch %= 500;
    }
    if (ch > 0 && ch >= 100) {
      ans += ch / 100;
      ch %= 100;
    }
    if (ch > 0 && ch >= 50) {
      ans += ch / 50;
      ch %= 50;
    }
    if (ch > 0 && ch >= 10) {
      ans += ch / 10;
      ch %= 10;
    }
    if (ch > 0 && ch >= 5) {
      ans += ch / 5;
      ch %= 5;
    }
    if (ch > 0 && ch >= 1) {
      ans += ch / 1;
    }
    
    cout << ans << endl;
  }
}

C++: #include <cstdio>

int main() {
	int num,n,i,a,b;
	a=0,b=0,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 <bits/stdc++.h>
using namespace std;

static const int coins[]{500, 100, 50, 10, 5, 1};

int main() {
  while (true) {
    int p;
    cin >> p;
    if (!p)
      break;
    int ans{};
    p = 1000 - p;
    for (int i{}; i < 6; ++i) {
      ans += p / coins[i];
      p %= coins[i];
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int change, money, pay;
	int c[6] = {500, 100, 50, 10, 5, 1};	

	cin >> pay;
	money = 1000 - pay;
	change = 0;
	
	rep(i, 6){
		change += money / c[i];	
		money = money % c[i];
	}

	cout << change << endl;

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    while(1) {
        int n;
        cin>>n;
        if(n==0) break;
        n=1000-n;
        vector<int> a={500,100,50,10,5,1};
        int ans=0;
        FORE(x,a) {
            ans+=n/x;
            n%=x;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  int M;
  cin >> M;
  int m = 1000 - M;

  int ans = 0;
  while (m > 0) {
    if (m >= 500) {
      m -= 500;
    } else if (m >= 100) {
      m -= 100;
    } else if (m >= 50) {
      m -= 50;
    } else if (m >= 10) {
      m -= 10;
    } else if (m >= 5) {
      m -= 5;
    } else {
      m--;
    }

    ans++;
  }

  cout << ans << endl;

  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

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

#define REP(i, n) for (int i = 0; i < (n); i++)

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

  while (cin >> n){
    int cnt = 0;
    for (int i = 0; i < 6; i++){
      while (n + coin[i] <= 1000){
        n += coin[i];
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

C++: #include<stdio.h>

int mian(void){
	int n,k;

	while(0==0){
		scanf("%d",&n);
		if(n==0)break;
		k=0;
		k += n /500;  n %=500;
		k += n/100;   n %=100;
		k += n/50;    n %= 50;
		k += n/10;    n %= 10;
		k += n/5;     k += n%5;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  
  cin >> money;
  oturi = 1000 - money;
  for(int i = 1000;oturi > 10;i /= 10){
    oturi %= i;
    if(oturi >= i/10){
      (oturi / (i/10) >= 5) ? (maisu += oturi / (i/10) - 4) : (maisu += oturi / (i/10));
    }
  }
  cout << maisu << endl;
    
    return 0;
  }

C++: #include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	while (1)
	{
		inin(x); if (x == 0)break;
		x = abs(x - 1000);
		int ans = 0;
		ans += x / 500; x %= 500;
		ans += x / 100; x %= 100;
		ans += x / 50; x %= 50;
		ans += x / 10; x %= 10;
		ans += x / 5; x %= 5;
		ans += x;
		cout << ans << endl;
	}
}

C++: #include<iostream>

const int coins[] = {500, 100, 50, 10, 5, 1};
//int nums[] = {0, 0, 0, 0, 0, 0};

int run(){
	int x, x2, num = 0, t;
	int M = sizeof(coins) / sizeof(int);
	std::cin >> x;
	if( x == 0 ){ return 0; }
	x2 = 1000 - x;
	for( int i = 0; i < M; i++ ){
		t = x2 / coins[i];
		x2 -= t * coins[i];
		num += t;
	}
	std::cout << num << std::endl;
	return 1;
}

int main(){
	while( run() );
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int s=0,h=0,ft=0,t=0,f=0,o=0,money=1000,genkin,sum=0;
	money=money-genkin;
	s=money/500;
	money=money-s*500;
	h=money/100;
	money=money-h*100;
	ft=money/50;
	money=money-ft*50;
	t=money/10;
	money=money-t*10;
	f=money/5;
	money=money-f*5;
	o=money/1;
	sum=s+h+ft+t+f+o;
	printf("%d",sum);

	return 0;
}

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