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<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
#include<cstdio>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007
#define MAX_H 101
#define MAX_W 101


int main(){

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


    int n;
    while(cin >> n,n){
        int count = 0;
        int change = 1000-n;
        for(int i = 0;i < 6;i++){
            while(change >= money[i]){
                count++;
                change-=money[i];
            }
        }
        cout << count << endl;
    }



    return 0;
}

C++: using namespace std;
int main(){
	int n,c; int coin[]={500,100,50,10,5,1};
	while(cin>>n,n){
		c=0,n=1000-n; for(int i=0;i<6;i++)c+=n/coin[i],n%=coin[i];
		cout<<c<<endl;
	}
	return 0;
}

C++: #include <cstdio>

int main()
{
  int n;
  while (scanf("%d", &n), n)  
  {
      int left = 1000 - n;
      int coin[] = { 500, 100, 50, 10, 5, 1 };
      int res = 0;
      for (int i = 0; left; ++i)
	  while (left >= coin[i])
	      ++res, left -= coin[i];
      printf("%d\n", res);
  }
}

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


int main(){
    while (1){
	int n;
	
	int m = 0;
	cin >> n;
	if (n == 0) break;
	n = 1000 - n;
	
	while (n >= 500){
	    m++;
	    n -= 500;
	}
	while (n >= 100){
	    m++;
	    n -= 100;
	}
	while (n >= 50){
	    m++;
	    n -= 50;
	}
	while (n >= 10){
	    m++;
	    n -= 10;
	}
	while (n >= 5){
	    m++;
	    n -= 5;
	}
	while (n >= 1){
	    m++;
	    n -= 1;
	}

	cout << m << endl;
    
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
	int a;
	int i = 0;
	cin >> a;
	int b = 1000 - a;
	while (b>=500)
	{
		b = b - 500;
		i = i + 1;
	}
	while (b >= 100)
	{
		b = b - 100;
		i = i + 1;
	}
	while (b >= 50)
	{
		b = b - 50;
		i = i + 1;
	}
	while (b >= 10)
	{
		b = b - 10;
		i = i + 1;
	}
	while (b >= 5)
	{
		b = b - 5;
		i = i + 1;
	}
	while (b >= 1)
	{
		b = b - 1;
		i = i + 1;
	}
	cout << i << endl;
	return 0;
}

C++: #include <stdio.h>

int main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

	return 0;

}

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

int main() {
	int a,b,c,d,e,f,g;
	cin >> a;
	b=1000-a;
	c=b%500;
	d=c%100;
	e=d%50;
	f=e%10;
	g=f%5;
	cout<<b/500+c/100+d/50+e/10+f/5+g<<endl;
	return 0;
}

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

int memo[1111];
int p[] = {500, 100, 50, 10, 5, 1};

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  for(int i=0;i<6;i++) ans = min(ans, solve(n-p[i])+1);
  
  return memo[n] = ans;
}

int main(){

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;
        int c = 1000 - n;
        int sum = 0;
        sum = c / 500 + c % 500 / 100 + c % 500 % 100 / 50 + c % 500 % 100 % 50 / 10 + c % 500 % 100 % 50 % 10 / 5 + c % 500 % 100 % 50 % 10 % 5;
        cout << sum << endl;
    }

    return 0;
}

C++: #include <iostream>
 
using namespace std;
 
int main()
{
	int change,money;

	while(1){
	cin>>money;
	if(money<1||money>1000){
		break;
	}else{
		int  coin,coin1,coin2,coin3,coin4,coin5,coin6;

		change=1000-money;

		coin1=change/500;
		coin2=change%500/100;
		coin3=change%500%100/50;
		coin4=change%500%100%50/10;
		coin5=change%500%100%50%10/5;
		coin6=change%500%100%50%10%5/1;

		coin=coin1+coin2+coin3+coin4+coin5+coin6;
		cout<<coin<<"\n";
	
		}
	}



    return 0;
}

C++: #include <cstdio>
using namespace std;
int main()
{
 int a;
 scanf("%d",&a);
 a=1000-a;
 printf("%d\n",a/500+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);
}

C++:  #include <functional>
 #include <algorithm>
 #include <iostream>
 #include <numeric>
 #include <iomanip>
 #include <utility>
 #include <cstdlib>
 #include <sstream>
 #include <bitset>
 #include <vector>
 #include <cstdio>
 #include <ctime>
 #include <queue>
 #include <deque>
 #include <cmath>
 #include <stack>
 #include <list>
 #include <map>
 #include <set>
 
 using namespace std;
 
 typedef vector<int> vi;
 typedef pair<int,int> pii;
 typedef long long ll;
 
 #define dump(x)  cerr << #x << " = " << (x) << endl
 #define rep(i,n) for(int i=0;i<(n);i++)
 #define all(a)  (a).begin(),(a).end()
 #define pb push_back
 #define sz size()
 
 const double EPS = 1e-10;
 const int INF = 100000000;
 
 int solve(int n){
 int ret=0;
 int m[]={500,100,50,10,5,1};
 rep(i,6){
 ret+=n/m[i];
 n-=m[i]*(n/m[i]);
 }
 return ret;
 }
 
 
 int main(){
 vi a,b;
 rep(j,10){
 int k;
 cin>>k;
 a.pb(k);
 }
 rep(j,10){
 int k;
 cin>>k;
 b.pb(k);
 }
 sort(all(a));
 sort(all(b));
 
 cout<<(a[9]+a[8]+a[7])<<" "<<(b[9]+b[8]+b[7])<<endl;
 
 return 0;
 }

C++: //
//  main.cpp

#include <iostream>
using namespace std;


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

C++: #include <iostream>
using namespace std;
int main(){
  int n=1000 ,m ,coin=0;
  while( true ){
    cin >> m;

    if( m == 0 ){
      break;
    }
    n -= m;
    if( n >= 500 ){
      coin += n / 500;
      n %= 500;
    }
    
    if( n >= 100 ){
      coin += n / 100;
      n %= 100;
    } 
    
    if( n >= 50 ){
      coin += n / 50;
      n %= 50;
    } 
    
    if( n >= 10 ){
      coin += n / 10;
      n %= 10;
    } 
    
    if( n >= 5 ){
    coin += n / 5;
    n %= 5;
    }
    
    if( n >= 1 ){
      coin += n;
    }
  
    cout << coin << endl;
    n = 1000;
    coin = 0;
  }
}

C++: #include<cstdio>
#include<iostream>
int main(){
    while(1){
        int x;
        int coin,n=0;
        scanf("%d",&x);
        if(x==0)
            break;
        x=1000-x;
        for(int i=0;i<6;i++){
            if(i==0)
                coin=500;
            else if(i==1)
                coin=100;
            else if(i==2)
                coin=50;
            else if(i==3)
                coin=10;
            else if(i==4)
                coin=5;
            else
                coin=1;
            for(;x>=coin;){
                x-=coin;
                n++;
            }
        }
        printf("%d\n",n);
    }
    return 0;
}