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(){
	while(1){
	int n;
	cin>>n;
	if(n==0)break;
	int a,b,c,d,e,f,g;
	g=1000-n;
	for(a=0;a<2;a++){
		for(b=0;b<5;b++){
			for(c=0;c<2;c++){
				for(d=0;d<5;d++){
					for(e=0;e<2;e++){
						for(f=0;f<5;f++){
							if(a*500+b*100+c*50+d*10+e*5+f==g){
								cout<<a+b+c+d+e+f<<endl;
								break;
							}
						}
					}
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main() {
	while(true){
		int x;
		cin>>x;
		if(x==0){
			break;
		}
 
		int ans=0,change=1000-x,money[6]={500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			int n=change/money[i];
			ans+=n;
			change-=money[i]*n;
		}
 
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  int c[6]={500,100,50,10,5,1};
  while(cin>>n,n){
    int m=1000-n,a=0;
    for(int i=0;i<6;++i){
      a+=m/c[i];
      m-=m/c[i]*c[i];
    }
    cout<<a<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
 int n;
 cin >> n;
 int remaind = 1000 - n;
 int ans = 0;
 for (int i = 0; i < 6; i++)
 {
  ans += remaind / coins[i];
  remaind %= coins[i];
 }
 cout << ans << endl;
 return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r(v.size()); partial_sum(v.begin(), v.end(), r); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    acum(vector<T>& v, T b=0){ return accumulate(v.begin(), v.end(), b); }
TEMP_T vector<T> inpt(int n){ vector<T> v(n); for (int i=0; i<n; i++) cin >> v[i]; return v; }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int solve(){
  }
};

int main()
{
  int n;
  while (n = in()){
    n = 1000 - n;
    int v = 0;
    for (int i = 0; i < 6; i++){
      static const int c[] = {500, 100, 50, 10, 5, 1};
      v += n / c[i];
      n %= c[i];
    }
    printf("%d\n", v);
  }

  return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> coins={500,100,50,10,5,1};
    int a;
    while(cin >> a,a){
        a=1000-a;
        int ans=0;
        rep(i,6) ans+=a/coins[i],a%=coins[i];
        cout << ans << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
int n;cin>>n;
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<endl;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int pay,remain,ans=0;

	while(1){
		cin>>pay;
		if(pay==0){
			break;
		}
		remain=1000-pay;
		ans=0;
		while(remain>=500){
			remain-=500;
			ans++;
		}
		while(remain>=100){
			remain-=100;
			ans++;
		}
		while(remain>=50){
			remain-=50;
			ans++;
		}
		while(remain>=10){
			remain-=10;
			ans++;
		}
		while(remain>=5){
			remain-=5;
			ans++;
		}
		while(remain>=1){
			remain-=1;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int solve(int n){
	n=1000-n;
	int ans=0;

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

	for(int i=0;i<6;++i) while(n>=change[i]) n-=change[i],ans++;
		
	return ans;
}

int main(void){
	int n;
	while(cin >>n,n){
		cout << solve(n) << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	n=1000-n;
	ans+=n/500;n%=500;
	ans+=n/100;n%=100;
	ans+=n/50;n%=50;
	ans+=n/10;n%=10;
	ans+=n/5;n%=5;
	ans+=n;
	cout<<ans<<endl;
}

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

	int coins[6] = { 500,100,50,10,5,1 };
int main() {
	while (1)
	{
	int n, ans = 0;
	cin >> n;
	if (n == 0)break;
	n = 1000 - n;
	for (int i = 0; i < 6; i++)
	{
		ans += n / coins[i];
		n %= coins[i];
	}
	cout << ans << endl;
	}
	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;
	scanf("%d",&genkin);
	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\n",sum);

	return 0;
}

C++: #include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int m[] = {500,100,50,10,5,1};
    while(1){
    int n;
    scanf("%d",&n);
    if(n == 0)
        break;
    n = 1000 - n;
    
    int c = 0;int i = 0;
    while(n > 0){
        if(n < m[i]){
            i++;
        }else{
            n -= m[i];
            c++;
        }
    }
    printf("%d\n",c);
    }
    return 0;
}

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

int main()
{
int a,b,c;
a=0;
cin>>c;
b=1000-c;

while(b>=500){
a++;
b=b-500;
}
while(b>=100){
a++;
b=b-100;
}
while(b>=50){
a++;
b=b-50;
}
while(b>=10){
a++;
b=b-10;
}
while(b>=5){
a++;
b=b-5;
}
while(b>=1){
a++;
b=b-1;
}
cout<<a<<'\n';
return 0;
}

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

int main(){
	int change, pay, cnt;
	while(true){
		cin>>pay; if(pay==0) break;
		cnt=0;
		change = 1000 - pay;
		cnt+=  change / 500 ;
		cnt+= (change / 100) %5;
		cnt+= (change / 50)  %2;
		cnt+= (change / 10)  %5;
		cnt+= (change / 5)   %2;
		cnt+=  change 	   %5;
		cout<<cnt<<endl;
	}
	return 0;
}