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 buy,oturi,kouka;
cin>>buy;
if(!buy==0){

oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
}
return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
#include <map>
using namespace std;
int main(){
	
	int n;
	int x=0;
	int s[6]={500,100,50,10,5,1};
	cin>>n;
	
	n=1000-n;
	int k=0;
	while(n>0){
		if(n-s[k]>=0){
			n=n-s[k];
			x++;
		}
		else
			k++;
	}
	
	cout<<x<<endl;
	

}

C++: #include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main() {
	while (true) {
		int coin = 0;
		int price = 0;

		cin >> price;
		if (price == 0) {
			break;
		}

		for (auto temp : { 500, 100, 50, 10, 5, 1 }) {
			const auto temp_div = div(price, temp);
			coin += temp_div.quot;
			price = temp_div.rem;
		}

		cout << coin << endl;
	}
	return 0;
}

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

// #define MP make_pair
// #define PB push_back
// #define ALL(x)  (x).begin(),(x).end()
// #define RALL(x) (x).rbegin(),(x).rend()
// #define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
// #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
// #define rep(i, N)  for (int i = 0; i < (int)(N); i++)
// #define rrep(i, N) for (int i = N - 1; i >= 0; i--)
// #define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
// #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
// #define PB push_back

using namespace std;

// typedef long long LL;
// typedef unsigned long long ULL;
// typedef vector<int> VI;
// typedef vector<VI > VVi;
// typedef vector<string> VS;
// typedef vector<LL> VLL;
// typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int sum=0;
    int x;
    int cnt=0;
    while(1){
        cin>>x;
        if(!x)
            return 0;
        sum=1000-x;
        while(sum>0){
            if(sum>=500){
                cnt++;
                sum-=500;
            }
            else if(sum>=100){
                cnt++;
                sum-=100;
            }
            else if(sum>=50){
                cnt++;
                sum-=50;
            }
            else if(sum>=10){
                cnt++;
                sum-=10;
            }
            else if(sum>=5){
                cnt++;
                sum-=5;
            }
            else{
                cnt++;
                sum-=1;
            }
        }
        cout<<cnt<<endl;
        cnt=0;
    }


    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
int siharai=1;
int oturi;
int a;

while(siharai!=0){
cin>>siharai;
oturi=0;
if(siharai==0)
break;

oturi=1000-siharai;

if(oturi>500){
a+=1;
oturi-=500;
}


while(oturi>=100){

a+=1;
oturi-=100;


}

while(oturi>=50){

a+=1;
oturi-=50;


}

while(oturi>=10){

a+=1;
oturi-=10;


}

while(oturi>=5){

a+=1;
oturi-=5;

}

while(oturi>=1){

a+=1;
oturi-=1;


}
cout<<a<<'\n';
a=0;
}

return 0;

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int C[6] = {500, 100, 50, 10, 5, 1};
int main(void){
	int n;
	while(cin >> n, n){
	n = 1000-n;
	int cnt = 0;
	int val = 0;
	while(n != 0){
		if(n - C[val] < 0){
			val++;
		}else{
			n -= C[val];
			cnt++;
		}
	}
	FIN(cnt);
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int main() {
    int a[5], sum[5] = { 0 };
    int i = 0;
    while(a[i]) {
        std::cin >> a[i];
        if (a[i] == 0) {
            break;
        }
        i++;
        
    }
	i = 0;
    while (a[i] != 0) {
        sum[i] += (1000 - a[i]) / 500;
        a[i] = (1000 - a[i]) % 500;
        sum[i] += a[i] / 100;
        a[i] = a[i] % 100;
        sum[i] += a[i] / 50;
        a[i] = a[i] % 50;
        sum[i] += a[i] / 10;
        a[i] = a[i] % 10;
        sum[i] += a[i] / 5;
        a[i] = a[i] % 5;
        sum[i] += a[i];
        i++;
    }
    for (int j = 0; j<i; j++) {
        std::cout << sum[j] << std::endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n;
    int pay ;
    int cent=0;
    
    cin >> n;
    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent;
    return 0;
    
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	while(cin >> n, n) {
		n = 1000 - n;
		int r = 0;
		r += n / 500; n %= 500;
		r += n / 100; n %= 100;
		r += n / 50; n %= 50;
		r += n / 10; n %= 10;
		r += n / 5; n %= 5;
		r += n;
		cout << r << endl;
	}
	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>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int kane;
int oturi[6]={500,100,50,10,5,1};
int mai;

int main(){
	while(1){
		mai=0;
		cin>>kane;
		kane=1000-kane;
		if(kane==0) break;
		for(int i=0;i<6;i++){
			mai+=(kane/oturi[i]);
			kane%=oturi[i];
		}
		cout<<mai<<endl;
	}
		
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  int money,oturi,maisu = 0;
  int money2[6] = {500,100,50,10,5,1};
  
  cin >> money;
  oturi = 1000 - money;

  for(int i = 0;i < 6;i++){
    maisu += oturi / money2[i];
    oturi %= money2[i];
  }
  cout << maisu << endl;
    
    return 0;
  }