Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

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

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007




int main(){
	int n;
	while(cin >> n && n > 0){
		n = 1000 - n;
		int ans = 0;
		ans += n / 500;
		n %= 500;
		ans += n / 100;
		n %= 100;
		ans += n / 50;
		n %= 50;
		ans += n / 10;
		n %= 10;
		ans += n /5;
		n %= 5;
		ans += n / 1;
		cout<<ans<<endl;
	}
}