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>
using namespace std;

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

int main(){
	int cnt = 0,i = 5;
	cin >> X;
	X = 1000-X;
	while( X > 0 ){
		while( X >= change[i] ){
			X -= change[i];
			cnt++;
		}
		i--;
	}
	cout << cnt << endl;
	return 0;
}

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

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

int main(void){
    // Your code here!
    int tmp;
    while(cin>>tmp){
        if(tmp == 0){
            break;
        }
        int sum = 1000 - tmp;
        int cnt = 0;
        int s = 0;
        bool flag = false;
        while(true){
            if(sum == 0){
                flag = true;
                break;
            } else if(sum - coin[s] >= 0){
                sum -= coin[s];
                cnt += 1;
            } else{
                s++;
            }
            
        }
        
        cout << cnt << endl;

    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	for (int u = 0; u < 5; u++)
	{
		int co = 0;
		int a = 0;
		cin >> a;
		if (a == 0)
		{
			break;
		}

		int o = 0;
		o = 1000 - a;
        for (int i = 0; i < 100; i++)
        {
	        if (o == 0)
	        {
		        break;
	        }
	        if (o >= 500)
		    {
			    co++;
			    o -= 500;
		    }
		    else if (o >= 100)
		    {
			    co++;
			    o -= 100;
		    }
		    else if (o >= 50)
		    {
			    co++;
			    o -= 50;
		    }
		    else if (o >= 10)
		    {
			    co++;
			    o -= 10;
		    }
		    else if (o >= 5)
		    {
			    co++;
			    o -= 5;
		    }
		    else if (o >= 1)
		    {
			    co++;
			    o -= 1;
		    }
        }
		cout << co << endl;
	}
}

C++: #include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>
#include<chrono>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define timenow std::chrono::system_clock::now()
#define timecal(start,end) std::chrono::duration_cast<std::chrono::milliseconds>((end)-(start)).count()

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))


constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  cin >> n;
  n = 1000-n;
  if(n >= 500){
    n -= 500;
    ++ans;
  }
  while(n >= 100){
    ++ans;
    n -= 100;
  }
  if(n >= 50){
    n -= 50;
    ++ans;
  }
  while(n >= 10){
    ++ans;
    n -= 10;
  }
  if(n >= 5){
    n -=5;
    ++ans;
  }
  cout << ans + n << endl;
  return 0;
}

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

const int data[6]={500,100,50,10,5,1};
int main() {
	// your code goes here
	int n;
	while(cin>>n && n){
		n=1000-n;
		int ans=0;
		for(int i=0;i<6;i++){
			ans+=n/data[i];
			n%=data[i];
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num;
	
	while (scanf("%d", &price), price){
		back = PAY - price;
		num = 0;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d\n", num);
	}
	return 0;
}

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(void){
    while(1){
    int a;
	int n;
	int c=0;
	cin>>a;
    if(a==0)break;
	int count=0;
	for(n=1000-a;n!=0;c++){
        if(n>=500)n-=500;
        else if(n>=100)n-=100;
        else if(n>=50)n-=50;
        else if(n>=10)n-=10;
        else if(n>=5)n-=5;
        else if(n>=1)n-=1;
    }
    cout << c << endl;

    }
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void){
    while(true){
        int num;
        cin >> num;
        if(num==0) break;
        num=1000-num;
        int sum=0;
        sum+=num/500;
        num%=500;
        sum+=num/100;
        num%=100;
        sum+=num/50;
        num%=50;
        sum+=num/10;
        num%=10;
        sum+=num/5;
        num%=5;
        sum+=num;
        cout << sum << "\n";
    }
    
    return 0;
}

C++: #include <stdio.h>

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 5; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
}

C++: #include <iostream>

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

C++: #include <stdio.h>

const int money[] = { 500, 100, 50, 10, 5, 1 };
const int size = sizeof( money ) / sizeof( int );

int main ( void )
{
	int x, i, answer = 0;

	while ( 1 ) {
		scanf( "%d", &x );
		if ( x == 0 ) {
			break;
		}

		for ( i = 0; i < size; ++i ) {
			answer += x / money[i];
			x %= money[i];
		}

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

	return 0;
}

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

int main(){
	vector<int> coin{500, 100, 50, 10, 5, 1};
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		n = 1000 - n;
		int ans = 0;
		for(int i=0; i<(int)coin.size(); i++){
			while(coin[i] <= n){
				n -= coin[i];
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		n = 1000 - n;
		int answer = 0;
		for(int i = 0; n > 0; i++){
			while(n >= COINS[i]){
				n -= COINS[i];
				answer++;
			}
		}
		printf("%d\n", answer);
	}
	return 0;
}