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;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n != 0){
	
		int a = 1000 - n;
		int cnt = 0;
		for(int i = 0; i < 6; ++i){
			while(a >= coin[i]){
				a -= coin[i];
				++cnt;
			}
		}
		
		cout << cnt << endl;
	}

	return 0;
}

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

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

int main() {

	int change, coins;

	while (cin >> change, change) {
		change = 1000 - change;

		coins = 0;
		for (int i = 0; i < 6; ++i) {
			if (change >= coin[i]) {
				coins += change / coin[i];
				change %= change / coin[i];
				if (!change)
					break;
			}
		}
		cout << coins << endl;
	}
	return 0;
}

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

int change[6]={1,5,10,50,100,500};
int cnt;
int n;

int main(){
	cin >> n;
	n = 1000-n;
	for( int i = 5; i >= 0; i-- ){
		while(n>=change[i]){
			n-=change[i];
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int coin[]={500,100,50,10,5,1};
int main() {int n,r,i;while(1){cin>>n;if(!n)break;n=1000-n,r=0;for(i=0;i<6;i++)r+=n/coin[i],n%=coin[i];cout<<res<<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 >4){ count -= 4;}
      res /=10;
    }
    cout << count << endl;
  }
}

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

int main(){
    int price,change;
    int money[6]={500, 100, 50, 10, 5, 1};
    while(1){
    int cnt=0;
    cin >> price;
    if(price == 0)break;
    change = 1000 - price;
    for(int i = 0;i < 6;i++){
        while(1){
            if(change >= money[i]){
                change -= money[i];
                cnt++;
            }
            else break;
        }
    }
    cout << cnt << endl;
    }
    return 0;
}

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 <iostream>

int main(void){
  int price;

  while(1){
    int cnt = 0;
    std::cin >> price;
    if(price == 0)  return 0;
    price = 1000 - price;
    while(1){
      if(price >= 500){
        cnt++; price -= 500;
      }else if(price >= 100){
        cnt++; price -= 100;
      }else if(price >= 50){
        cnt++;  price -= 50;
      }else if(price >= 10){
        cnt++; price -=10;
      }else if(price >= 5){
        cnt++; price -= 5;
      }else{
        cnt += price;
        break;
      }
    }
    std::cout << cnt << std::endl;
  }
}

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

C++: #include <stdio.h>

int main(void)
{
	int in;
	int out[1000] = {0};

	int rem = 0;
	int rnd = 0;


	while(1)
	{
		scanf("%d",&in);

		if(in == 0)
			break;

		rem = 1000 - in;

		while(rem)
		{
			if(rem >= 500){
				rem -= 500;
				out[rnd]++;
				}else

			if(rem >= 100){
				rem -= 100;
				out[rnd]++;
				}else

			if(rem >= 50){
				rem -= 50;
				out[rnd]++;
				}else

			if(rem >= 10){
				rem -= 10;
				out[rnd]++;
				}else

			if(rem >= 5){
				rem -=5;
				out[rnd]++;
				}else

			if(rem >= 1){
				rem -= 1;
				out[rnd]++;
				}
		}

		rnd++;

	}



	for( in = 0 ; in < rnd ; in++){
		printf("%d\n",out[in]);}

	return 0;
}

C++: #include <iostream>

using namespace std;

int n,a,b,c,d,e,f;

int main(void){

  while( cin >> n , n ){

    n = 1000 - n;
    a = b = c = d = e = f = 0;

    while( n >= 500 ){
      a++;
      n -= 500;
    }
    while( n >= 100 ){
      b++;
      n -= 100;
    }
    while( n >= 50 ){
      c++;
      n -= 50;
    }
    while( n >= 10 ){
      d++;
      n -= 10;
    }
    while( n >= 5 ){
      e++;
      n -= 5;
    }
    while(n){
      f++;
      n--;
    }
    cout << a + b + c + d + e + f << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

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

	
	return 0;
	
}

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

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

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){
  int t,a,ans,cnt;
  while(1){
    ans=0,cnt=0;
    cin >> t;
    if(t==0){
      break;
    }
    a=1000-t;
    if(500<=a){
      cnt=a/500;
      ans=a/500;
      a=a-(cnt*500);
    }


    if(100<=a){
      cnt=a/100;
      ans+=a/100;
      a=a-(cnt*100);
    }

    if(50<=a){
      cnt=a/50;
      ans+=a/50;
      a=a-(cnt*50);
    }

    if(10<=a){
      cnt=a/10;
      ans+=a/10;
      a=a-(cnt*10);
    }

    if(5<=a){
      cnt=a/5;
      ans++;
      a=a-5;
    }

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

C++: #include <iostream>

using namespace std;

int main() {

	int n;

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

		cout << t << endl;
	}

	return 0;

}

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

int main(){
	int money=1000,m;
	for(int m;cin>>m;money=1000){
		if(m==0)break;
		money-=m;
		int count;
		for(count=0;money;){
			//cout<<"money:"<<money<<endl;
			if(money/500){
				money-=500;
			}
			else if(money/100){
				money-=100;
			}
			else if(money/50){
				money-=50;
			}
			else if(money/10){
				money-=10;
			}
			else if(money/5){
				money-=5;
			}
			else if(money/1){
				money-=1;
			}
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}