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 <bits/stdc++.h>

using namespace std;

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

int getCoin(int &rest, int coinVal) {
	int cnt;

	cnt = rest / coinVal;
	rest %= coinVal;

	return cnt;
}

int main() {
	int n, rest, sum;

	while (cin >> n, n) {
		sum = 0;
		rest = 1000 - n;
		for (int i = 0; i < 6;++i){
			sum += getCoin(rest, CoinType[i]);
		}
		cout << sum << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	cin>>a;
	a=1000-a;
	if(a>499){
		a=a-500;
		s=s+1;
	}
	for(i=0;i<4;i++){
		if(a>99){
			a=a-100;
			s=s+1;
		}
	}
	if(a>49){
		a=a-50;
		s=s+1;
	}
	for(i=0;i<4;i++){
		if(a>9){
			a=a-10;
			s=s+1;
		}
	}
	if(a>4){
		a=a-5;
		s++;
	}
	s=s+a;
	cout<<s<<endl;
}

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

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

C++: #include<iostream>
using namespace std;
int main(){
  int mon,cnt=0;
  cin >> mon;
  mon=1000-mon;
  while(1){
    if(mon<5)break;
    if(mon>=500){mon-=500;cnt++;}
    else if(mon>=100 && mon<500){mon-=100;cnt++;}
    else if(mon>=50 && mon<100){mon-=50;cnt++;}
    else if(mon>=10 && mon<50){mon-=10;cnt++;}
    else if(mon>=5 && mon<10){mon-=5;cnt++;}
  }
  cnt+=mon;
  cout<< cnt << endl;
  return 0;
}

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

int main(){
	int x, y;
	while(scanf("%d", &x))
		if(x == 0){
			break;
		}{
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

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

using namespace std;

#define print(a) printf("%d\n", a)

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

#define MAX(a,b) ((a)>(b)?(a):(b))


int main(){
	int co, mod, ch = 0;
	
	cin >> co;
	
	mod = 1000 - co;
	
	ch += mod/500;
	mod = mod%500;
	
	ch += mod/100;
	mod = mod%100;
	
	ch += mod/50;
	mod = mod%50;
	
	ch += mod/10;
	mod = mod%10;
	
	ch += mod/5;
	mod = mod%5;
	
	ch += mod;
	
	cout << ch << 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=0,ans=0;
  
  cin>>num;
  num=1000-num;
  while(num!=0){
    ans += num/money[i];
    num = num%money[i];
    i++;
  }
  printf("%d\n",ans);
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
const int coin[6] = {1,5,10,50,100,500};
const int sen = 1000;
int main(){
  int n;
  cin >> n;
  int oturi = sen - n;
  int sum = 0;
  int cnt = 5;
  while(oturi != 0){
    if(oturi/coin[cnt] != 0){
      sum++;
      oturi -= coin[cnt];
    }
    else{
      cnt--;
    }
  }
  cout << sum << endl;
  return 0;
}

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

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

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

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

int main(){
  int n;
  int coin[] = {500, 100, 50, 10, 5, 1};

  while(cin >> n, n){
    n = 1000 - n;
    int sum = 0;
    for(int i = 0; i < 6; i++){
      sum += n / coin[i];
      n %= coin[i];
    }
    cout << sum << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m;
    
    while(true){
        cin >> m;
        if(m == 0) break;
        
        int o; //おつり
        o = 1000 - m;
        int count = 0;
        if(o >= 500){
            count = count + o / 500;
            o = o % 500;
            if(o >= 100){
                count = count + o / 100;
                o = o % 100;
            }
            if(o >= 50){
                count = count + o / 50;
                o = o % 50;
            }
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
       
        
        else if(o >= 100 && o < 500){
            
            count = count + o / 100;
            o = o % 100;
            
            if(o >= 50){
                count = count + o / 50;
                o = o % 50;
            }
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        
        else if(o >= 50 && o < 100){
            
            count = count + o / 50;
            o = o % 50;
            
            if(o >= 10){
                count = count + o / 10;
                o = o % 10;
            }
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        
        else if(o >= 10 && o < 50){
            
            count = count + o / 10;
            o = o % 10;
            if(o >= 5){
                count = count + o / 5;
                o = o % 5;
            }
            count = count + o;
            cout << count << endl;
        }
        
        else if(o >= 5 && o < 10){
            count = count + o / 5;
            o = o % 5;
            count = count + o;
            cout << count << endl;
        }
        
        else{
            count = count + o;
            cout << count << endl;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

		int a[6] = {500, 100, 50, 10, 5, 1};
		int ans = 0;
		rep(i, 6) {
			if(m >= a[i]) {
				ans += m / a[i];
				m %= a[i];
			}
		}

		cout << ans << endl;
	}


	return 0;
}