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<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
				cnt++;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

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

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

    vector<int> pays;
    while (1) {
        int tmp;
        cin >> tmp;
        if (tmp == 0) {
            break;
        } else {
            pays.push_back(tmp);
        }
    }

    vector<int> coins = {500, 100, 50, 10, 5, 1};
    for (auto pay : pays) {
        int back = 1000 - pay; // お釣り
        int ans = 0;
        for (auto coin : coins) {
            int use = back / coin; // coin円 を使用する枚数
            back -= coin * use;
            ans += use;
        }
        cout << ans << endl;
    }
    return 0;
}

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

C++: #include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int cost;

	while(cin >> cost)
	{
		if (cost == 0) break;

		int change, changenum;
		change = 1000 - cost;
		changenum = 0;

		if (change > 500)
		{
			change -= 500;
			changenum += 1;
		}

		for (int i = 0; change >= 100; i++)
		{
			change -= 100;
			changenum += 1;
		}

		for (int i = 0; change >= 50; i++)
		{
			change -= 50;
			changenum += 1;
		}

		for (int i = 0; change >= 10; i++)
		{
			change -= 10;
			changenum += 1;
		}
		
		for (int i = 0; change >= 5; i++)
		{
			change -= 5;
			changenum += 1;
		}

		changenum += change;

		cout << changenum << endl;
	}

	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,cnt=0,cmp;
    vector<int> q;
    int w[6]={500,100,50,10,5,1};
    while(1){
        cin >> a;
        if(a==0){break;}
        q.push_back(a);
    }
    int g=q.size();
    for(int j=0;j<g;j++){
        cmp=1000-q[j];
        for(int i=0;i<6;i++){
            cnt+=cmp/w[i];
            cmp-=w[i]*(cmp/w[i]);
        }
        cout << cnt << endl;
        cnt=0;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int gold,change,count;
  while(cin>>gold){
    if(gold==0) break;
    change = 1000 - gold;
    count = 0;
    while(change!=0){
      if(change>=500){
	count++;
	change -= 500;
      }
      else if(change<500&&change>=100){
	count++;
	change -= 100;
      }
      else if(change<100&&change>=50){
	count++;
	change -= 50;
      }
      else if(change<50&&change>=10){
	count++;
	change -= 10;
      }
      else if(change<10&&change>=5){
	count++;
	change -= 5;
      }
      else if(change<5&&change>=1){
	count++;
	change -= 1;
      }
    }
    cout << count << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

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

int main(){
	int n;
	while(cin >> n && n){
		n = 1000 - n;
		int cnt = 0;
		rep(i, 6){
			cnt += n / nums[i];
			n %= nums[i];
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){

 int num,oturi,m = 0;

while(1){
 
cin>>num;

      if(num==0){
         break;
  }else{
    
  oturi=1000-num;

   
 
    m = oturi/500;
 
    m = m+oturi%500/100;
 
    m = m+oturi%500%100/50;
  
    m = m+oturi%500%100%50/10;
 
    m = m+oturi%500%100%50%10/5;

    m = m+oturi%500%100%50%10%5/1;

    num = 0;

     
   }
  cout<<m<<'\n';
  
}

return 0;
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

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

int main(){
	int n; scanf("%d",&n);
	int m=1000-n;
	int res=0;
	for(int i=0;i<6;i++){ res+=m/c[i]; m%=c[i]; }
	printf("%d\n",res);
}

C++: #include <stdio.h>

int main(void)
{
	int money;
	int change;
	int coin;
	
	while (scanf("%d", &money) != EOF){
		coin = 0;
		if (money != 0){
			if (change / 500 != 0){
				coin += change / 500;
				change %= 500;
			}	
			if (change / 100 != 0){
				coin += change / 100;
				change %= 100;
			}
			if (change / 50 != 0){
				coin += change / 50;
				change %= 50;
			}
			if (change / 10 != 0){
				coin += change / 10;
				change %= 10;
			}
			if (change / 5 != 0){
				coin += change / 5;
				change %= 5;
			}
			if (change != 0){
				coin += change;
			}
		}
		printf("%d\n", coin);
	}
	
	return (0);
}

C++: #include <iostream>

using namespace std;

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

int main() {
  int m = 0;
  int n;
  while(cin >> m, m) {
    n = 0;
    m = 1000 - m;
    for (int i = 5; i >= 0; i--) {
      int t = m / coins[i];
      n += t;
      m -= t * coins[i];
    }
    cout << n << endl;
  }
}

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

int main(){
	
	int c[6]={500,100,50,10,5,1};
	int n;
	
	
	while(cin>>n){
		if(n!=0){
		int k=0;
		int s=0;
		n=1000-n;
	
	while(n>0){
		if(n-c[k]>=0){
			n=n-c[k];
			s++;
		}
		else
			k++;
	}
			cout<<s<<endl;
	}
	
	else
		break;
	}
	
}

C++: #include<iostream>
using namespace std;
int main(){
int n,b;while(true){cin>>b;n=1000-b;;if(n==0){break;}
cout<<n/500+(n/100)%5+(n/50)%2+(n/10)%5+(n/5)%2+n%5<<endl;}}

C++: #include<iostream>
using namespace std;
int main(){
int price,cnt=0;
while(1){
cin>>price;
if(price==0)break;
price=1000-price;
if(price%500!=0){
cnt+=(price%500);
price-=(price%500);
}
if(price%100!=0){
cnt+=(price%100);
price-=(price%100);
}
if(price%50!=0){
cnt+=(price%50);
price-=(price%50);
}
if(price%10!=0){
cnt+=(price%10);
price-=(price%10);
}
if(price%5!=0){
cnt+=(price%5);
price-=(price%5);
}
if(price!=0){
cnt+=price;
}
cout<<cnt<<endl;
}
return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	for (;;)
	{
		int a,b,c,d,e,f,g,h,i,j,k,l,n,m;
		d=0;
		cin>>a;
		if (a==0)
		{
			break;
		}
		b=1000-a;
		c=b/500;
		d=d+c;
		e=b%500;
		c=e/100;
		d=d+c;
		e=b%100;
		c=e/50;
		d=d+c;
		e=b%50;
		c=e/10;
		d=d+c;
		e=b%10;
		c=e/5;
		d=d+c;
		e=b%5;
		d=d+e;
		cout<<d<<endl;
	}
	return 0;
}