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 <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)

int main()
{
  int p[] = {500,100,50,10,5,1};
  int data;
  while(cin >> data,data){
    data = 1000 - data;
    int cnt = 0;
    Rep(i,6) {
      while(p[i] <= data) {
	data -= p[i];cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	while(1){
	int n;
	cin>>n;
	if(n==0)break;
	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;
}

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


int main(void){

	while( true ) {
		int n;
		cin >> n;
		if( !n ) break;
		n = 1000 - n;
		int ans = 0;
		int p[] = { 500, 100, 50, 10, 5, 1 };
	
		for( int i = 0; i < 6; i++ ) {
			ans += n / p[i];
			n %= p[i];
		}
		cout << ans << endl;
	}

    return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;


int main(){

	int coin[6] ={ 500,100,50,10,5,1 },sum,price;

	while(true){
		scanf("%d",&price);
		if(price == 0)break;

		sum = 0;

		price = 1000 - price;

		for(int i = 0; i <= 5; i++){
			while(price >= coin[i]){
				price -= coin[i];
				sum++;
			}
		}

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

    return 0;
}

C++: #include <iostream>

int ans;
int count(int change)
{
	if(!change)
		return 0;
	if(change >= 500){
		ans += change / 500;
		count(change % 500);
	}
	else if(change >= 100){
		ans += change / 100;
		count(change % 100);
	}
	else if(change >= 50){
		ans += change / 50;
		count(change % 50);
	}
	else if(change >= 10){
		ans += change / 10;
		count(change % 10);
	}
	else if(change >= 5){
		ans += change / 5;
		count(change % 5);
	}
	else if(change >= 1){
		ans += change / 1;
		count(change % 1);
	}
}

int main()
{
	int pay;
	while(1){
		ans=0;
		std::cin >> pay;
		if(!pay)
			break;

		int change = 1000 - pay;

		count(change);

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

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!

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

 int s=1000-t;
 int w=s/500;
 int e=(s%500)/100;
  int r=((s%500)%100)/50;
  int y=(((s%500)%100)%50)/10;
  int u=((((s%500)%100)%50)%10)/5;
  int o=(((((s%500)%100)%50)%10)%5);
  cout<< w+e+r+y+u+o <<endl;
}
 
}

C++: #include <iostream>

using namespace std;

int main() {
	int a;
	cin >> a;
	a = 1000 - a;
	int counter = 0;
	if (a >= 500) {
		counter += a/500;
		a %= 500;
	}
	if (a >= 100) {
		counter += a/100;
		a %= 100;
	}
	if (a >= 50) {
		counter += a/50;
		a %= 50;
	}
	if (a >= 10) {
		counter += a/10;
		a %= 10;
	}
	if (a >= 5) {
		counter += a/5;
		a %= 5;
	}
	if (a >= 1) {
		counter += a;
	}
	cout << counter << endl;
	return 0;
}

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

C++: #include <iostream>
#include <string>
#include <list>
#include <vector>
#include <deque>
#include <numeric>

using namespace std;
int main() {
	int n;
	int fh, h, fty, ten, f, i;
	int th = 1000;
	for (;;) {
		cin >> n;
		if (n == 0)break;
		th -= n;
		fh = th / 500;
		th -= 500 * fh;
		h = th / 100;
		th -= 100 * h;
		fty = th / 50;
		th -= 50 * fty;
		ten = th / 10;
		th -= 10 * ten;
		f = th / 5;
		th -= 5 * f;
		i = th;
		cout << fh + h + fty + ten + f + i << endl;
		th = 1000;
	}
	


}

C++: // quest1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	int money, reverse, count = 0;

	scanf("%d", &money);
	reverse = 1000 - money;

	while (reverse >= 500) {
		reverse -= 500;
		count++;
	}
	while (reverse >= 100) {
		reverse -= 100;
		count++;
	}
	while (reverse >= 50) {
		reverse -= 50;
		count++;
	}
	while (reverse >= 10) {
		reverse -= 10;
		count++;
	}
	while (reverse >= 5) {
		reverse -= 5;
		count++;
	}
	while (reverse >= 1) {
		reverse -= 1;
		count++;
	}

	printf("%d", count);

    return 0;
}

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

int main(){
	int x, y = 0;
	scanf("%d", &x);
	x = 1000 - x;
	while (x >= 500){
		x -= 500;
		y++;
	}
	while (x >= 100){
		x -= 100;
		y++;
	}
	while (x >= 50){
		x -= 50;
		y++;
	}
	while (x >= 10){
		x -= 10;
		y++;
	}
	while (x >= 5){
		x -= 5;
		y++;
	}
	while (x >= 1){
		x -= 1;
		y++;
	}
	printf("%d\n", y);
	return 0;
}

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

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

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

const int coins[] = {500, 100, 50, 10, 5, 1};
int main(){
  int m;
  while(cin >> m){
    if(m==0)break;

    m = 1000 - m;
    int res = 0;
    for(int i=0;i<6;i++){
      while(m >= coins[i]){
	res++;
	m -= coins[i];
      }
    }
    cout << res << endl;
  } 
}

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;
}