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 coin[6] = {500,100,50,10,5,1};

void slove(int money){
	int count=0;
	for(int i=0; i<6; i++){
		while(money >= coin[i]){
			count++;
			money-=coin[i];
		}
	}
	cout << count << endl;
}

int main(){
	int money;
	while(cin >> money)
		slove(1000-money);
	return 0;
}

C++: #include <cstdio>

using namespace std;

int main()
{
    int amount;
    int change[] = {500, 100, 50, 10, 5, 1};
    int money = 1000;
    int count = 0;
    int i = 0;

    while (scanf("%d", &amount), amount){
        money -= amount;

        while (i < 6){
            if (money - change[i] >= 0){
                money -= change[i];
                count++;
            }
            else {
                i++;
            }
        }

        printf("%d\n", count);
    }

    return (0);
}

C++: 
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>

#include<vector>
#include<set>

using namespace std;

const int mod=1000000007;

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

	while (1) {
		int n, ans = 0;
		cin >> n;
		if (n == 0)break;

		n = 1000 - n;


		for (int i = 0; i < 6; i++) {
			ans += n / t[i];
			n %= t[i];
		}

		cout << ans << endl;

	}
	
    return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
m=1000-m;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans<<endl;

}

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define debug(x) #x << "=" << (x)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

int main() {

    int price;
    while(true) {
        cin >> price;
        if (price == 0) break;

        int change = 1000 - price;
        int coins[] = {500, 100, 50, 10, 5, 1};
        int ans = 0;
        for (int c : coins) {
            int num = change / c;
            ans += num;
            change -= c * num;
        }

        cout << ans << "\n";
    }

    return 0;
}

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

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

int main(){
	while(cin >> n){
		if(!n)break;
		n = 1000-n;
		for( int i = 5; i >= 0; i-- ){
			while(n>=change[i]){
				n-=change[i];
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a = 0;
	int b;
	int c = 0;
	for (; a != 0;)
	{
		cin >> a;
		b = a;
		for (; b != 0;)
		{
			if (b >= 500)
			{
				b = b - 500;
				c++;
			}
			if (b >= 100)
			{
				b = b - 100;
				c++;
			}
			if (b >= 50)
			{
				b = b - 50;
				c++;
			}
			if (b >= 10)
			{
				b = b - 10;
				c++;
			}
			if (b >= 5)
			{
				b = b - 5;
				c++;
			}
			if (b >= 1)
			{
				b = b - 1;
				c++;
			}
			cout<<c<<endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>

int main(){
int n,c;
while(1){

scanf("%d",&n);
if(n==0)break;
c=0;
n=1000-n;
do{
if(n>=500){n-500;c++;}
else if(n>=100){n-100;c++;}
else if(n>=50){n-50;c++;}
else if(n>=10){n-10;c++;}
else if(n>=5){n-5;c++;}
else if(n>=1){n-1;c++;}
}while(n!=0);
printf("%d\n",c);
}
return 0;
}

C++: #include <cstdio>
#include <iostream>

using namespace std;

int all,ans;

void m(int d){
    ans += all / d;
    all = all % d;
}

int solve(int a){
    all = 1000 - a;
    ans = 0;
    m(500);
    m(100);
    m(50);
    m(10);
    m(5);
    m(1);
    return ans;
}

int main(){
    int a;
    while(true){
        cin >> a;
        if(!a){break;}
        cout << solve(a) << endl;
    }
}

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

const int C[6] {1, 5, 10, 50, 100, 500,};

int N;
void solve(){
    int ret = 0;
    for(int i = 5; i > -1; --i){
        int t = N/C[i];
        N -= t*C[i];
        ret += t;
    }
    cout << ret << '\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1) {
        cin >> N;
        if(N == 0) break;
        N = 1000 - N;
        solve();
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int ans = 0;
  ans += (1000 - t)/500;
  ans += ((1000 - t)/100) - 5*((1000 - t)/500);
  ans += ((1000 - t)/10)-10*((1000 - t)/100);
  cout << ans << endl;
}

C++: #include <stdio.h>

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
  return -1;
}

C++: #include<iostream>
using namespace std;
int main(){
int siharai,oturi=1;
int a,b,c,d,e,f;

while(oturi!=0){
cin>>siharai;
oturi=1000-siharai;

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

while(oturi>=100){
if(oturi>=100){
b=1;
oturi=oturi-100;
}
else
a=0;
}

while(oturi>=50){
if(oturi>=50){
c=1;
oturi=oturi-50;
}
else
c=0;
}

while(oturi>=10){
if(oturi>=10){
d=1;
oturi=oturi-10;
}
else
d=0;
}

while(oturi>=5){
if(oturi>=5){
e=1;
oturi=oturi-5;
}
else
e=0;
}

while(oturi>=1){
if(oturi>=1){
f=1;
oturi=oturi-1;
}
else
f=0;
}
}
cout<<a+b+c+d+e+f<<'\n';
return 0;

C++: #include <stdio.h>

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 5; j++){
    i2 = 0;
    scanf("%d",&i1);
    if(i1 == 0) break;
    i1 = 1000 - i1; 
 
    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }

    i4[j] = i2;    
  }

  for(int n : i4) if(n != 0) printf("%d\n",n);
  return 0;
}

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

int main(void)
{
	int much;
	int c = 0;

	cin >> much;

	much = 1000 - much;

	if(much >= 500){
		much %= 500;
		c++;
	}
	if(much >= 100){
		c += (int)(much / 100);
		much %= 100;
	}
	if(much >= 50){
		c += (int)(much / 50);
		much %= 50;
	}
	if(much >= 10){
		c += (int)(much / 10);
		much %= 10;
	}
	if(much >= 5){
		c += (int)(much / 5);
		much %= 5;
	}
	c += much;

	cout << c << endl;


	return 0;
}