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 <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

int main()
{
  cin >>N;
  N =1000-N;
  int ans = 0;
  int c[6] ={500,100,50,10,5,1};
  for(int i =0;i < 6;i++){
   while(N/c[i]){
      ans++;
      N -=c[i];
    }
  }
  cout <<ans<<endl;
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c,l,k,h,j,r,f;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/50;
	i=z%50;
	l=i/10;
	k=i%10;
	h=k/5;
	j=k%5;
	r=j/1;
	f=j%1;
	c=b+y+m+l+h+r;
	printf("%d\n",c);
	return 0;
}

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(!n)break;
		int rest=1000-n;
		int fihu=rest/500;
		int hun=(rest-fihu*500)/100;
		int fif=(rest-fihu*500-hun*100)/50;
		int ten=(rest-fihu*500-hun*100-fif*50)/10;
		int five=(rest-fihu*500-hun*100-fif*50-ten*10)/5;
		int one=rest%5;
		cout<<fihu+hun+fif+ten+five+one<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main ()
{
	int a,b,c,d,e,f,g;
    while(1){
	cin>>a;
    if(a==0)
        break;
	b=(1000-a)/500;
	c=(1000-(a+500*b))/100;
	d=(1000-(a+500*b+100*c))/50;
	e=(1000-(a+500*b+100*c+50*d))/10;
	f=(1000-(a+500*b+100*c+50*d+10*e))/5;
	g=(1000-(a+500*b+100*c+50*d+10*e+5*f))/1;
        cout<<b+c+d+e+f+g<<endl;}
	return 0;
}

C++: #include <stdio.h>

int N;
int coin[6] = { 500,100,50,10,5,1 };
int ans = 0;

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		ans = 0;
		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int pay=0,coin=0;
	cin>>pay;
	pay=1000-pay;
	cout<<pay<<endl;
	if(pay/500>=1){
		pay-=500;
		coin++;
	}
	if(pay>=100){
		coin+=pay/100;
		pay-=100*(pay/100);
	}
	if(pay>=50){
		coin+=pay/50;
		pay-=50*(pay/50);
	}
	if(pay>=10){
		coin+=pay/10;
		pay-=10*(pay/10);
	}
	if(pay>=1){
		coin+=pay;
	}
	cout<<coin<<endl;
}

C++: #include <iostream>

using namespace std;

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

int main() {
    int pay;
    int change;
    int num;
    
    while(cin >> pay, pay){
    	change = 1000 - pay;
    	num = 0;
    	for(int i=0;i<6;++i){
    		num += change / coins[i];
    		change =  change % coins[i];
    	}
    	cout << num << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
int n,b;while(true){cin>>b;n=1000-b;;if(b==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 n,m;
	cin >> n;
	m = 0;

	while( n <= 500 ){
		n = n-500;
		m++;
	}
	while( n <= 100 ){
		n = n-100;
		m++;
	}
	while( n <= 50 ){
		n = n-50;
		m++;
	}
	while( n <= 10 ){
		n = n-10;
		m++;
	}
	while( n <= 5 ){
		n = n-5;
		m++;
	}
	while( n <= 1){
		n = n-1;
		m++;
	}

	cout << m <<cout;

	return 0;
}

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

int main() 
{
	int a;
	cin >> a;
	int b =1000-a;
	int c = 0;
	c += b / 500;
	b -= b / 500 * 500;
	c += b / 100;
	b -= b / 100 * 100;
	c += b / 50;
	b -= b / 50 * 50;
	c += b / 10;
	b -= b / 10 * 10;
	c += b / 5;
	b -= b / 5 * 5;
	c += b;
	cout << c << endl;
}

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

int main(){
	int C[6] = {500, 100, 50, 10, 5, 1};	// 0:500円 1:100円 2:50円 3:10円 4:5円 5:1円
	int price;
	int change = 1000;
	int coin = 0;
	
	for(;;){
		change = 1000;
		coin = 0;
		cin >> price;
		if(price == 0)	break;
		change -= price;
	
		for(int i = 0; i < 6; i++){
			coin += change / C[i];
			change %= C[i];
		}
	
		cout << coin << endl;
	}
	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;
	while(scanf("%d",&n)&&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<iostream>
using namespace std;
int main()
{
  int money,count = 0,oturi[1000] = {};
  int money2[6] = {500,100,50,10,5,1};

  for(int i = 0;i >= 0;i++){
    cin >> money;
    count++;
    if(money == 0)
      break;
    oturi[i] = 1000 - money;
  }

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

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

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

int main() {
	int a,b=0;
	while(1){
		cin >> a;
		if(a==0) break;
		a=1000-a;
		if(a>500){
			a-=500;
			b++;
		}
	
		while(1){
			if(a<100) break;
			a-=100;
			b++;
		}

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

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