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>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
	int money = 0;

	int change = 0;



	while (1)
	{


		int count500 = 0;

		int count100 = 0;

		int count50 = 0;

		int count10 = 0;

		int count5 = 0;

		int count1 = 0;


		cin >> money;

		if (money == 0)break;


		change = 1000 - money;

		count500 = change / 500;

		count100 = (change - (count500 * 500)) / 100;

		count50 = (change - (count500 * 500) - (count100 * 100)) / 50;

		count10 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50)) / 10;

		count5 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10)) / 5;

		count1 = (change - (count500 * 500) - (count100 * 100) - (count50 * 50) - (count10 * 10) - (count5 * 5)) / 1;

		cout << count500 + count100 + count50 + count10 + count5 + count1 << endl;
	}

	return 0;
}

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

int main()
{

	int price, change, coin_num, cnt;
	int coin_kind[] = {500, 100, 50, 10, 5, 1};

	while(cin >> price, price > 0) {
		coin_num = 0;
		cnt = 0;
		change = 1000 - price;
		while(change > 0) {
			if(change - coin_kind[cnt] >= 0) {
				coin_num++;
				change -= coin_kind[cnt];
			}
			else {
				cnt++;
			}
		}
		cout << coin_num << endl;
	}

	return 0;

}

C++: #include<iostream>
using namespace std;
int main(){
int n;while(true){cin>>n;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>
#include <algorithm>
using namespace std;
int main(){
	int n,m,a,b,c,d,e,f;
	cin>>n;
	m=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*1==m){
								cout<<a+b+c+d+e+f<<endl;
								break;
                            }
							}
						}
					}
				}
			}
	    }
	return 0;
	}

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
}

C++: #include <stdio.h>

void main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

}

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		cin>>n;
		int c=1000-n,ans=0;
		while(c>=500) c-=500,++ans;
		while(c>=100) c-=100,++ans;
		while(c>=50) c-=50,++ans;
		while(c>=10) c-=10,++ans;
		while(c>=5) c-=5,++ans;
		while(c>=1) c-=1,++ans;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,c;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	c=0;
	n=1000-n;
	while(n>=500){
		n=n-500;
		c++;
	}
	while(n>=100){
		n=n-100;
		c++;
	}
	while(n>=50){
		n=n-50;
		c++;
	}	
	while(n>=10){
		n=n-10;
		c++;
	}
	while(n>=5){
		n=n-5;
		c++;
	}	
	while(n>=1){
		n=n-1;
		c++;
	}
	printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

	for(int i=0;i<n;i++)
	{
		cout << p[i][0] + p[i][1] + p[i][2] << endl;
	}
	*/

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/

	//おつり
	int onum[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << onum[1] << onum[2] << onum[3] << onum[4] << endl;
	return 0;
}

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

int main(void)
{
	int much;

	while(cin >> much, much > 0){
		int c = 0;

		much = 1000 - much;

		if(much >= 500){
			c += (int)(much / 500);
			much %= 500;
		}
		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;
}

C++: #include <bits/stdc++.h>
using namespace std;
constexpr int c[] = { 500, 100, 50, 10, 5, 1 };

int main() {
  int a;
  while (cin >> a, a) {
    int b = 1000 - a;
    int ans = 0;
    for (int i = 0; i < 6; i++) {
      ans += b / c[i];
      b %= c[i];
    }
    cout << ans << "\n";
  }
}

C++: #include <iostream>

using namespace std;

int main() {
  while (true) {
    int M;
    cin >> M;
    if (M == 0) {
      break;
    }
    int m = 1000 - M;

    int ans = 0;
    while (m > 0) {
      if (m >= 500) {
        m -= 500;
      } else if (m >= 100) {
        m -= 100;
      } else if (m >= 50) {
        m -= 50;
      } else if (m >= 10) {
        m -= 10;
      } else if (m >= 5) {
        m -= 5;
      } else {
        m--;
      }

      ans++;
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=51){
		i++;
		n=(n-50);
	}
	if (n>=11){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=6){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	// Dynamic Programming
	// dp[àz] = Å¬

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

	int n;
	while ( cin >> n && n )
	{
		vector <int> dp( (1000-n)+1, 0 );
		for ( int i = 0; i < 6; i++ ) dp[coins[i]] = 1;

		for ( int i = 0; i < (1000-n)+1; i++ )
		{
			if ( dp[i] > 0 )
			{
				for ( int j = 0; j < 6; j++ )
				{
					if ( i + coins[j] < (1000-n)+1 )
					{
						if ( dp[i+coins[j]] == 0 ) dp[i+coins[j]] = dp[i] + 1;
						else dp[i+coins[j]] = min( dp[i+coins[j]], dp[i] + 1 );
					}
				}
			}
		}

		cout << dp[(1000-n)] << endl;
	}

	return 0;
}

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

int main()
{
  int n;
  while(cin >> n, n){
    int cnt = 0, co[6] = {500, 100, 50, 10, 5, 1};
    n = 1000 - n;

    for (int i = 0; i < 6; i++){
      int a = n / co[i];
      cnt += a;
      n -= a * co[i];
    }

    cout << cnt << endl;
  }
  return 0;
}