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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0521

int main() {
    int coins[]{500, 100, 50, 10, 5, 1};
    while(true) {
        int p; cin >> p;
        if (p == 0) break;
        int change = 1000 - p;
        int ans = 0;
        for (int c : coins) {
            int v = change / c;
            ans += v;
            change -= v * c;
        }
        cout << ans << "\n";
    }

    return 0;
}

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

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    
    while (cin >> n, n) {
        n = 1000 - n;

        int a = n / 500;
        n %= 500;

        int b = n / 100;
        n %= 100;

        int c = n / 50;
        n %= 50;

        int d = n / 10;
        n %= 10;

        int e = n / 5;
        int f = n % 5;

        int ans = a + b + c + d + e + f;
        cout << ans << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(){
  
  while(1){
    
    int n,cnt=0;
  
  scanf("%d",&n);
  
  if(n==0){break;}

  n=1000-n;
  
  while(n>=500){
    n-=500;
    cnt++;
  }
  while(n>=100){
    n-=100;
    cnt++;
  }
  while(n>=50){
    n-=50;
    cnt++;
  }
  while(n>=10){
    n-=10;
    cnt++;
  }
  while(n>=5){
    n-=5;
    cnt++;
  }
  while(n!=0){
    n--;
    cnt++;
  }

  printf("%d\n",cnt);
  
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll n,ans;
vector<int> abcd(4);

  
int main(){
  vector<int> price={500,100,50,10,5,1};
  while(1){
    int x;
    cin >> x;
    if(x==0)break;
    int y = 1000-x;
    int coins=0;
    rep(i,6){
      int t = y/price[i];
      y -= t*price[i];
      coins += t;
    }
    cout << coins << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,o,s,m;
	
	scanf("%d",&m);
	while(m!=0){
		a=0;
		b=0;
		c=0;
		d=0;
		e=0;
		f=0;
		s=0;
		
		o=1000-m;
		a=o/500;
		o=o-500*a;
		b=o/100;
		o=o-100*b;
		c=o/50;
		o=o-50*c;
		d=o/10;
		o=o-10*d;
		e=o/5;
		o=o-5*e;
		f=o/1;
		o=o-1*f;
	
	s=a+b+c+d+e+f;
	
	printf("%d\n",s);
	scanf("%d",&m);
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0521 : Change **/
int main()
{
	int n;
	int c[] = {500, 100, 50, 10, 5, 1};
	while (cin>>n, n) {
		n = 1000 - n;
		
		int ans = 0;
		rep(i, 6) {
			while (n>=c[i]) {
				n-=c[i];
				ans++;
			}
		}
		cout << ans << endl;
	}
}

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(){
  
  for(int i=0;i<1111;i++) solve(i);

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

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

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

int main()
{
    int n;
    while(cin >> n && n)
    {
        int ans = 0;
        n = 1000 - n;

        REP(MAXC)while(n >= coin[i]){ n-= coin[i]; ans++;}
        
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){

	int n;
	int money[6] = {500,100,50,10,5,1};
	while(cin >> n, n){
		
		int change = 0;
		n = 1000 - n;
		rep(i,6){
			
			change += n / money[i];
			n = n % money[i];
		}
		cout << change << endl;
	}

	return 0;
}

C++: #include <stdio.h>

int main() {
    while (1) {
        int i;
        int value, change;
        int array[6] = {500, 100, 50, 10, 5, 1};
        int times = 0; 
        int tmp;

        scanf("%d", &value);
        if (!value) return 0;

        change = 1000 - value;

        tmp = change;
        for (i=0;i<6;i++) {
            times += (tmp/array[i]);
            tmp %= array[i];
        }

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

C++: #include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	for(;;){
		int a,b=0,c=0;
		cin>>a;
		if(a==0)break;
		b=1000-a;
		c=(b/500)+((b%500)/100)+(((b%500)%100)/50)+((((b%500)%100)%50)/10)+(((((b%500)%100)%50)%10)/5)+(((((b%500)%100)%50)%10)%5);
		cout<<c<<endl;
	}
	return 0;
}

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

int main(){
  int num;
  int money[]={500,100,50,10,5,1};
  int i,ans;
    
  for(;;){
    cin>>num;
    if(num==0) break;
    
    i=0;ans=0;
    num=1000-num;
    while(num!=0){
      ans += num/money[i];
      num = num%money[i];
      i++;
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include<stdio.h>
int main(){
	int i=0,a,b[6]={500,100,50,10,5,1},c=0;
	scanf("%d",&a);
	a=1000-a;
	while(a){
		if((a-b[i])>=0){
			a-=b[i];
			c++;
		}
		else i++;
	}
	printf("%d\n",c);
}