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<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


int main(){

	int a[6]={500,100,50,10,5,1};
	int b,s;
	while(true){

	cin >> b;
	if(b==0) break;

	int coins=0;
	s=1000-b;
	rep(i,6){

	coins+=s/a[i]; s%=a[i];

	}

	cout << coins << endl;

	}

	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==0){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

C++: #include <iostream>
//#include <fstream>
#include <vector>
#include <string>
//#include <cstdlib>
//#include <algorithm>
//#include <set>
//#include <conio.h>
using namespace std;
 
int main(){
	int n;
	while(cin >> n&& n!=0){
		int sum=0,pri=1000-n;
		while(pri>=500){
			pri -=500;
			++sum;
		}
		while(pri>=100){
			pri -=100;
			++sum;
		}
		while(pri>=50){
			pri -=50;
			++sum;
		}
		while(pri>=10){
			pri -=10;
			++sum;
		}
		while(pri>=5){
			pri -=5;
			++sum;
		}
		while(pri>=1){
			pri -=1;
			++sum;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  n=1000-n;
  int a[]={500,100,50,10,5,1};
  int ans=0;
  for(int i=0;i<6;i++){
    while(n>=a[i]) n-=a[i],ans++;
  }
  cout<<ans<<endl;
  return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		N = 1000 - N;
		int ans = 0;
		set<int>s;
		s = { 500,100,50,10,5,1 };
		for (auto m : s) {
			ans += N / m;
			N /= m;
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

C++: #include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, m, c, j;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		m = 1000-n;
		c = 0;
		
		for(int i = 100; m != 0; i /= 10){
			j = 5 * i;
			if(m >= j){
				m -= j;
				c++;
			}
		
			while(m >= i){
				m -= i;
				c++;
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

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

int main() {

  long long int n;
  cin >> n;
  n = 1000 - n;

  long long int ans = 0;
  if ( n >= 500 ) {
    ans++;
    n -= 500;
  }
  ans += n / 100;
  n %= 100;

  if ( n >= 50 ) {
    ans++;
    n -= 50;
  }
  ans += n / 10;
  n %= 10;

  if ( n >= 5 ) {
    ans++;
    n -= 5;
  }
  ans += n / 1;

  cout << ans << endl;

  return 0;

}

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

   cout<<i<<endl;
return 0;
}

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

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

	int pay, change, i;
	
	cin >> pay;
	
	change = 1000 - pay;

	while(1){
	if(change == 0 || change == 1000) break;
	else if(change < 0 || 1000 < change) 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;
		}
	}
	}
	
	if(pay == 0 ) return 0;
        else if(pay < 0 || 1000 < pay) return 0;
	else cout << i << "\n";

	return 0;
}

C++: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> vec = {500,100,50,10,5,1};
    int N;
    cin >> N;
    while(N != 0){
        N = 1000 - N;
        int ans = 0;
        for(int i=0; i<6; i++){
            while(vec[i] <= N){
                N -= vec[i];
                ans++;
            }
        }
        cout << ans << enld;
        cin >> N;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

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