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 total = 0, cut = 0;
		cin >> total;
		if(total == 0) break;
		total = 1000 - total;
		cut += total / 500;
		total = total % 500;
		cut += total / 100;
		total = total % 100;
		cut += total / 50;
		total = total % 50;
		cut += total / 10;
		total = total % 10;
		cut += total / 5;
		total = total % 5;
		cut += total / 1;
		cout << cut << endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF       numeric_limits<int>::max()
#define NINF      numeric_limits<int>::min()
#define MOD       1000000007

using namespace std;
using Int = long long;

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

    vector<int> coin_vals{500, 100, 50, 10, 5, 1};

    while(true) {
        int in;
        std::cin >> in;
        if(in == 0) {
            break;
        }

        int ans    = 0;
        int change = 1000 - in;
        for(const auto& coin_val : coin_vals) {
            ans    += change / coin_val;
            change %= coin_val;
        }

        std::cout << ans << std::endl;
    }

    return 0;
}

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

using namespace std;

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

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

		int oturi = 1000-a;

		int ans = 0;

		for(int i = 0; i < 6; i++) {
			int coin = changes[i];
			while(oturi-coin>=0) {
				oturi -= coin;
				ans++;
			}
		}

		cout << ans << endl;
	}
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
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';
kouka=0;
}

return 0;
}

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	cin>>num1;
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int ans[11], an,n;
	an = 0;
	while (1) {
		cin >> n;
		if (n == 0) {
			goto a;
		}
		an = an + 1;
		ans[an] = 0;
		n = 1000 - n;
		while (n >= 500) {
			ans[an] = ans[an] + 1;
			n = n - 500;
		}
		while (n >= 100) {
			ans[an] = ans[an] + 1;
			n = n - 100;
		}
		while (n >= 50) {
			ans[an] = ans[an] + 1;
			n = n - 50;
		}
		while (n >= 10) {
			ans[an] = ans[an] + 1;
			n = n - 10;
		}
		while (n >= 5) {
			ans[an] = ans[an] + 1;
			n = n - 5;
		}
		while (n >= 1) {
			ans[an] = ans[an] + 1;
			n = n - 1;
		}
	}
a:;
	for (int i = 1; i <= an; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(){
  int coin[] = {500, 100, 50, 10, 5, 1};
  int n;
  while(std::cin >> n, n){
    int p = 0, ans = 0;
    n = 1000 - n;
    while(n != 0){
      while(n - coin[p] < 0)p++;
      n -= coin[p];
      ans++;
    }
    std::cout << ans << std::endl;
  }
  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 < 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 n;
  int c[] = {500,100,50,10,5,1};
  cin >> n;

  n = 1000-n;
  int ans =0;
  for( int i=0;i<6;i++ ){
    if( n >= c[i] ){
      ans += n / c[i];
      n = n% c[i];
    }
  }
  cout << ans << endl;
}

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


int main(){
    long long int n,ans=0;
    cin>>n;
    while(n!=0){
        n=1000-n;
        if(n/100>=5){
            ans+=n/100-4;
        }
        else{
            ans+=n/100;
        }
        if(n%10>=5){
            ans+=n%10-4;
        }
        else{
            ans+=n%10;
        }
        if((n/10)%10>=5){
            ans+=(n/10)%10-4;
        }
        else{
            ans+=(n/10)%10;
        }
        cout<<ans<<endl;
        ans=0;
        cin>>n;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
main(){
int money = 1000;int buy = 0;int maisuu = 0;
cin >> buy;
money = money - buy;
if(money >= 500){
 	maisuu = maisuu + 1;
 	money = money - 500 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/100;
 	money =money % 100;
  }
if(money >= 50){
 	maisuu = maisuu + 1;
 	money = money - 50 ;
 }
if(money >= 100){
 	maisuu = maisuu + money/10;
 	money =money % 10;
  }
money = money - buy;
if(money >= 5){
 	maisuu = maisuu + 1;
 	money = money - 5 ;
 }
maisuu = maisuu + money;
cout << maisuu << endl;
return 0;
}

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

int main() {
	int n,m,cnt;
	
	while(cin>>n){
		if(n==0)break;
		m=1000-n;
		
		for(;;){
			if(m>=500){
				m=m-500;
				//cout<<500<<endl;
				cnt++;
			}else if(m>=100&&500>m){
				m=m-100;
				//cout<<100<<endl;
				cnt++;
			}else if(m>=50){
				m=m-50;
				//cout<<50<<endl;
				cnt++;
			}else if(m>=10&&50>m){
				m=m-10;
				//cout<<10<<endl;
				cnt++;
			}else if(5<m){
				m=m-5;
				//cout<<5<<endl;
				cnt++;
			}else if(m<10){
				m=m-1;
				//cout<<1<<endl;
				cnt++;
			}
			if(m==0)break;
		}
		cout<<cnt<<endl;
		cnt=0;
	}
	
	return 0;
}

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

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1)
int b=a/1;
i+=a;
}
return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

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

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int coin[]={500,100,50,10,5,1};
	cin>>a;
	while(a!=0){
		a=1000-a;
		int total=0;
		int sheet=0;
		for(int i=0;i<6;i++){
			sheet=a/coin[i];
			a=a%coin[i];
			total+=sheet;
		}
		cout<<total<<endl;
		cin>>a;
	}
	return 0;
}