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 <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

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

using namespace std;

int main(){
	
	int answer;

	int in = 0, change = 0, n = 0;



	while (true) {
		n = 0;
		cin >> in;
		if (in == 0) break;
		change = 1000 - in;
		for (int i = 0; i < 6; i++) {
			while (change >= coin[i]) {
				change -= coin[i];
				n++;
			}
		}
	}

	answer = n;

	cout << answer << endl;

	return 0;
}

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

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

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

		for(int i=0; i < 6; i++){
			ans += n / p[i];
			n -= n / p[i] * p[i];
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(void){
    int m,a500,a100,a50,a10,a5,a1,k,sum=0;
    //cin >> m;
    
    while(true){
        cin >> m;
        if(m==0){
            break;
        }
        for(int i=0;i<5;i++){
            k=1000-m;
            a500=k/500;
            k=k%500;
            a100=k/100;
            k=k%100;
            a50=k/50;
            k=k%50;
            a10=k/10;
            k=k%10;
            a5=k/5;
            k=k%5;
            a1=k;
            sum=a500+a100+a50+a10+a5+a1;
        }
    
    cout << sum << endl;
    }
}

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

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

int main(){
  int i,j,n,ss,count=0,c[6]={1,5,10,50,100,500};

  while(cin >> n){
    j=0;
    count=0;
    ss=1000-n;
    for(i=5;i>=0;i--){
      if(ss>=c[i]){
	j+=ss/c[i];
	ss=ss%c[i];
      } 
    }
    cout << j << endl;
    
  }





}

C++: #include <stdio.h>

int main(void) {
	int n, i,cou = 0, list[6] = {500, 100, 50, 10, 5, 1};
	
	scanf("%d", &n);
	n = 1000 - n;
	for( i = 0; 6 > i; i++){
		cou += n/list[i];
		n %= list[i];
		
		if(n == 0) break;
	}
	printf("%d\n", cou);
	return 0;
}

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

int main()
{
int m;
while(cin>>m){
int ans=0;
while(m>=500){
ans++;
m-=500;
}
while(m>=100){
ans++;
m-=100;
}

while(m>=50){
ans++;
m-=50;
}
while(m>=10){
ans++;
m-=10;
}

while(m>=5){
ans++;
m-=5;
}

ans+=m;
cout<<ans<<endl;

}

}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int C[6] = {500, 100, 50, 10, 5, 1};
int main(void){
	int n;
	cin >> n;
	n = 1000-n;
	int cnt = 0;
	int val = 0;
	while(n != 0){
		if(n - C[val] < 0){
			val++;
		}else{
			n -= C[val];
			cnt++;
		}
	}
	FIN(cnt);

	return 0;
}

C++: #include <iostream>

using namespace std;

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

int main()
{
 int n;
 cin >> n;
 int remaind = 1000 - n;
 int ans = 0;
 for (int i = 0; i < 6; i++)
 {
  ans += remaind / coins[i];
  remaind %= coins[i];
 }
 cout << ans << endl;
 return 0;
}

C++: #include <stdio.h>
int main(){
	int a;
	while(1){
		int n=0;
		scanf("%d",&a);
		if(!a) break;
		a=1000-a;
		while(a>0){
			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;
			n++;
		}
		printf("%d\n",n);
	}
	return 0;
}

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

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

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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int y, b = 1000, c = 0;
  cin >> y;
  b -= y;
  for(int i = 0;; i++){
    if(b - 500 >= 0){
      b -= 500;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 100 >= 0){
      b -= 100;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 50 >= 0){
      b -= 50;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 10 >= 0){
      b -= 10;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 5 >= 0){
      b -= 5;
      c++;
      if(b == 0){
        break;
      }
    }else if(b - 1 >= 0){
      b -= 1;
      c++;
      if(b == 0){
        break;
      }
    }
  }
  cout << c << endl;
}

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

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

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

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

int main() {
	int input;							//テ・ツ?・テ・ツ環崚ァツ板ィ
	int yen[] = {500,100,50,10,5,1};	//テァツ。ツャティツイツィテ」ツ?ョテァツィツョテゥツ。ツ?
	
	while(1) {
		cin >> input;	//テ・ツ?・テ・ツ環?
		if(input == 0) break;

		int ans = 0;
		input = 1000 - input;
		while(input > 0) {

			for(int i = 0; i < 6; i++) {
				if (input >= yen[i]) {
					input -= yen[i];
					ans++;
					break;
				} 
			}

		}

		cout << ans << endl;
		
	}
	return 0;
}