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>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

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

C++: #include<iostream>
using namespace std;
int main()
{
  int money,count,maisu = 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[] = 1000 - money;
  }

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

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

using namespace std;

int main(){
	int price;
	int num[5] = {0};
	int i = 0;

	while (1){
		scanf("%d", &price);

		if (price != 0){
			price = 1000 - price;

			if (price / 500 != 0){
				num[i] += (price / 500);
				price -= (price / 500) * 500;	
			}
			if (price / 100 != 0){
				num[i] += (price / 100);
				price -= (price / 100) * 100;
			}
			if (price / 50 != 0){
				num[i] += (price / 50);
				price -= (price / 50) * 50;
			}
			if (price / 10 != 0){
				num[i] += (price / 10);
				price -= (price / 10) * 10;
			}
			if (price / 5 != 0){
				num[i] += (price / 5);
				price -= (price / 5) * 5;
			}
			if (price / 1 != 0){
				num[i] += price;
			}
		}
		else {
			break;
		}
		i++;
	}

	for (int i = 0; num[i] >= 1; i++){
		printf("%d\n", num[i]);
	}

}

C++: #include<iostream>
using namespace std;
int main(){
  int input;
  while(cin >> input){
    if(input == 0) break;
    input = 1000 - input;
    int hantei[6] = {500,100,50,10,5,1};
    int n = 0;
    for(int i=0;i<6;i++){
      n += input / hantei[i];
      input %= hantei[i];
    }
    cout << n << endl;
  }
}

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

int main() 
{ 
 int buy,oturi,kozeni,a,b,c,d,e,f; 
 while(1){
  cin>>buy;
  if(buy==0)
   break;
  else{
   oturi=1000-buy;
   a=oturi/500;
   if(a)b=(oturi-500)/100;
     else b=oturi/100;
   c=oturi%100/50;
   if(c)d=(oturi%100-50)/10;
     else d=oturi%100/10;
   e=oturi%10/5;
   if(e)f=oturi%10-5;
      else f=oturi%10;   

   kozeni=a+b+c+d+e+f;
   cout<<kozeni<<"\n";
  }
 }
 return 0; 
}

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

int main(){
  int a,i=0,b;
  while(cin>>a&&a){
    i=0;
    b=1000-a;
    i=b/500;
    b%=500;
    i+=b/100;
    b%=100;
    i+=b/50;
    b%=50;
    i+=b/10;
    b%=10;
    i+=b/5;
    b%=5;
    i+=b/1;
    cout<<i<<endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)

int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	while(true){
		int in,result=0,c[]{500,100,50,10,5,1};
		cin>>in;

		if(in==0) break;

		in*=-1;
		in+=1000;

		REP(i, 6){
			result+=in/c[i];
			in%=c[i];
		}

		cout<<result<<en;
	}


	return 0;
}

C++: /**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@17:33

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){


        while(1){

                int yen = 0;
                int oturi =0;
                int count = 0;

                cin >> yen;
                if(yen == 0)break;
                oturi = 1000 - yen;

                while(oturi/500 != 0){
                        oturi = oturi -500;
                        count++;        
                }
        

                while(oturi/100 != 0){
                        oturi = oturi -100;
                        count++;
                }
        

                while(oturi/50 != 0){
                        oturi = oturi -50;
                        count++;
                }
        

                while(oturi/10 != 0){
                        oturi = oturi -10;
                        count++;
                }
        

                while(oturi/5 != 0){
                        oturi = oturi -5;
                        count++;
                }
        

                count = count + oturi;        

                cout << count <<endl;

        }
    

        return 0;    


}

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 coin[6]={500,100,50,10,5,1};
    int n,c=0;
    for(;;){
        cin >> n;
        if(n==0) break;
        n=1000-n;
        for(int i=0;i<6;i++){
            for(;;){
                if(n>=coin[i]){
                    n-=coin[i];
                    c++;
                }
                else break;
            }
        }
        cout << c << endl;
        c=0;
    }

    return 0;
}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
    int m2,m3,m4,m5,m6,m7;

   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
 }
   
  return 0;
}