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 main() {
	int a,b=0;
	while(1){
		cin >> a;
		if(a==0) break;
		a=1000-a;
		if(a>500){
			a-=500;
			b++;
		}
	
		while(1){
			if(a<100) break;
			a-=100;
			b++;
		}

		if(a>50){
			a-=50;
			b++;
		}
	
		while(1){
			if(a<10) break;
			a-=10;
			b++;
		}
		
		if(a>5){
			a-=5;
			b++;
		}
		
		while(1){
			if(a==0) break;
			a-=1;
			b++;
		}
		cout << b << endl;
		b=0;
	}
	return 0;
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;

int gcd(int a, int b){return b?gcd(b, a % b):a;}
/*-------------------------------*/

int main(void)
{
  int list[6] = {500, 100, 50, 10, 5, 1};
  int n;
  int cnt;

  while (true){
    cin >> n;
    if (n == 0) break;
    n = 1000 - n;
    cnt = 0;
    REP(i, 6){
      if (i % 2 == 0){
        if (n - list[i] >= 0){
          cnt++;
          n -= list[i];
        }
      }
      else{
        if (n / list[i] != 0){
          cnt += n / list[i];
          n -= (n / list[i]) * list[i];
        }
      }
    }
    cout << cnt << endl;
  }
}

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

int main() {
	int all, rem, count = 0, tmp;
	while (1) {
		cin >> all;
		if (all == 0)
			break;
		rem = 1000 - all;
		if (rem >= 500) {
			count = count + 1;
			rem = rem - 500;
		}
		if (rem >= 100) {
			tmp = rem / 100;
			count = count + tmp;
			rem = rem - (100 * tmp);
		}
		if (rem >= 50) {
			tmp = rem / 50;
			count = count + tmp;
			rem = rem - 50 * tmp;
		}
		if (rem >= 10) {
			tmp = rem / 10;
			count = count + tmp;
			rem = rem - 10 * tmp;
		}
		if (rem >= 5) {
			tmp = rem / 5;
			count = count + tmp;
			rem = rem - 5 * tmp;
		}
		count = count + rem;
		cout << count << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int a,ans=0;
		cin>>a;
		if(a==0) break;
		a=1000-a;
		while(1){
			if(a==0) break;
			if(a>=500) a-=500;
			else if(a>=100) a-=100;
			else if(a>=50) a-=50;
			else if(a>=10) a-=10;
			else if(a>=5) a-=5;
			else if(a>=1) a-=1;
			ans++;
		}
		o(ans);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFll = 1e18;
#define put(n) cout<<(n)<<endl
#define Cout(n) cout<<(n)
#define rep(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define rrep(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define MP make_pair
#define pb(q) push_back(q)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,coin[6] = {500,100,50,10,5,1};
    
    while(cin>>N,N!=0){
        N = 1000 - N;
        int ans = 0;
        for(int i=0;i<6&&N!=0;){
            if(coin[i] <= N){
                N -= coin[i];
                ++ans;
            }
            else ++i;
        }
        put(ans);
    }
}

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

int main(){
while(1){
	int a[6]={500,100,50,10,5,1};
	int n,ans=0;
	scanf("%d",&n);
	if(n==0)break;
	n=1000-n;
	for(int i=0;i<6;i++){
		ans+=n/a[i];
		n%=a[i];
	}
	printf("%d\n",ans);
}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
int n;
int ca=0;
while(cin>>n&&n!=0){
int m=1000-n;
if(m>=500){
	m-=500;
	ca++;
		}
		if(m>=100){
			int i=m/100;
			ca+=i;
			m-=i*100;
			}
			if(m>=50){
				ca++;
				m-=50;
				}
				if(m>=10){
					int i=m/10;
					ca+=i;
					m-=i*10;
					}
					if(m>=5){
						ca++;
						m-=5;
						}
						if(m>=1){
							int i=m;
							ca+=i;
							}
						
		cout<<ca<<endl;
		ca=0;
		}
		return 0;					
		}

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

int main(
	int n,m;
	cin >> n;

	n = 1000 - n;
	m = 0;

	if ( n >= 500) {
		m = m + 1;
	}
	if ( n >= 100) {
		m = m + (n / 100);
	}
	if (n >= 50) {
		m = m + (n / 50);
	}
	if (n >= 10) {
		m = m + (n / 10);
	}
	if (n >= 5) {
		m = m + (n / 5);
	}
	if (n >= 1) {
		m = m + (n / 1);
	}

	cout << m << endl;

	return 0;
)

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

C++: #include <stdio.h>

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

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }

		int res = 1000 - N;
		while (res != 0) {
			if (res >= 500) {
				ans += res / 500;
				res -= 500 * (res / 500);
			}
			else if (res >= 100) {
				ans += res / 100;
				res -= 100 * (res / 100);
			}
			else if (res >= 50) {
				ans += res / 50;
				res -= 50 * (res / 50);
			}
			else if (res >= 10) {
				ans += res / 10;
				res -= 10 * (res / 10);
			}
			else if (res >= 5) {
				ans += res / 5;
				res -= 5 * (res / 5);
			}
			else { ans += res; res = 0; }
		}
	}
	printf("%d\n", ans);
	return 0;
}

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


int main(){

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


}

C++: #include <iostream>

using namespace std;

int main(){
  int money;
  while(cin >> money && money !=0){
    int count =0;
    int res = 1000 - money;
    for(int i=0;i<3;i++){
      //      cout << res << endl;
      count +=res %10;
      if(res % 10 >5){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}