Go: ///
// File:  0521.go
// Author: ymiyamoto
//
// Created on Wed Mar  7 22:11:28 2018
//
package main

import (
	"fmt"
)

var money int

func main() {
	for {
		fmt.Scan(&money)
		if money == 0 {
			break
		}
		rem := 1000 - money

		count := 0
		for _, coin := range []int{500, 100, 50, 10, 5, 1} {
			count += rem / coin
			rem %= coin
		}
		fmt.Println(count)
	}
}

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

using namespace std;

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

int main() {
	int a;
	while(true) {
		cin >> a;
		if(a==0) break;

		int oturi = 1000-a;

		int ans = 0;

		for(int i = 0; i < 6; i++) {
			int coin = changes[i];
			while(oturi-coin>=0) {
				oturi -= coin;
				ans++;
			}
		}

		cout << ans << endl;
	}
}

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

int main(){
int buy,oturi,kouka;
while(1){
cin>>buy;
if(buy==0){
break;
}
oturi=1000-buy;
if(oturi>500){
oturi-=500;
kouka+=1;
}
while(oturi>=100){
oturi-=100;
kouka+=1;
}
while(oturi>=50){
oturi-=50;
kouka+=1;
}
while(oturi>=10){
oturi-=10;
kouka+=1;
}
while(oturi>=5){
oturi-=5;
kouka+=1;
}
while(oturi>=1){
oturi-=1;
kouka+=1;
}
cout<<kouka<<'\n';
kouka=0;
}

return 0;
}

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

int main()
{
	int num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11,num12,num13;
	int sum;

	cin>>num1;
	num2=1000-num1;
	num3=num2/500;
	num4=num2%500;
	num5=num4/100;
	num6=num4%100;
	num7=num6/50;
	num8=num6%50;
	num9=num8/10;
	num10=num8%10;
	num11=num10/5;
	num12=num10%5;
	num13=num12/1;
	sum=num3+num5+num7+num9+num11+num13;
	cout<<sum;
	cout<<"\n";
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int ans[11], an,n;
	an = 0;
	while (1) {
		cin >> n;
		if (n == 0) {
			goto a;
		}
		an = an + 1;
		ans[an] = 0;
		n = 1000 - n;
		while (n >= 500) {
			ans[an] = ans[an] + 1;
			n = n - 500;
		}
		while (n >= 100) {
			ans[an] = ans[an] + 1;
			n = n - 100;
		}
		while (n >= 50) {
			ans[an] = ans[an] + 1;
			n = n - 50;
		}
		while (n >= 10) {
			ans[an] = ans[an] + 1;
			n = n - 10;
		}
		while (n >= 5) {
			ans[an] = ans[an] + 1;
			n = n - 5;
		}
		while (n >= 1) {
			ans[an] = ans[an] + 1;
			n = n - 1;
		}
	}
a:;
	for (int i = 1; i <= an; i++) {
		cout << ans[i] << endl;
	}
}

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

int main(){
  int coin[] = {500, 100, 50, 10, 5, 1};
  int n;
  while(std::cin >> n, n){
    int p = 0, ans = 0;
    n = 1000 - n;
    while(n != 0){
      while(n - coin[p] < 0)p++;
      n -= coin[p];
      ans++;
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main(){
  int i0[] = {500,100,50,10,5,1};
  int i1 = 1,i2 = 0;
  int i4[5] = {0};

  for(int j = 0; j < 6; j++){
    i2 = 0;
    scanf("%d",&i1);
    
    if(i1 == 0){   
      for(int n : i4) if(n != 0) printf("%d\n",n);
      return 0;
    }
    
    i1 = 1000 - i1;

    for(int n = 0; n < 6; n++){
      while(i1 >= i0[n]){
        i1 -= i0[n];
        i2++;
      }
    }
    i4[j] = i2;    
  }
  return -1;
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  int c[] = {500,100,50,10,5,1};
  cin >> n;

  n = 1000-n;
  int ans =0;
  for( int i=0;i<6;i++ ){
    if( n >= c[i] ){
      ans += n / c[i];
      n = n% c[i];
    }
  }
  cout << ans << endl;
}

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


int main(){
    long long int n,ans=0;
    cin>>n;
    while(n!=0){
        n=1000-n;
        if(n/100>=5){
            ans+=n/100-4;
        }
        else{
            ans+=n/100;
        }
        if(n%10>=5){
            ans+=n%10-4;
        }
        else{
            ans+=n%10;
        }
        if((n/10)%10>=5){
            ans+=(n/10)%10-4;
        }
        else{
            ans+=(n/10)%10;
        }
        cout<<ans<<endl;
        ans=0;
        cin>>n;
    }
    return 0;
}

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

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

int main() {
	int n,m,cnt;
	
	while(cin>>n){
		if(n==0)break;
		m=1000-n;
		
		for(;;){
			if(m>=500){
				m=m-500;
				//cout<<500<<endl;
				cnt++;
			}else if(m>=100&&500>m){
				m=m-100;
				//cout<<100<<endl;
				cnt++;
			}else if(m>=50){
				m=m-50;
				//cout<<50<<endl;
				cnt++;
			}else if(m>=10&&50>m){
				m=m-10;
				//cout<<10<<endl;
				cnt++;
			}else if(5<m){
				m=m-5;
				//cout<<5<<endl;
				cnt++;
			}else if(m<10){
				m=m-1;
				//cout<<1<<endl;
				cnt++;
			}
			if(m==0)break;
		}
		cout<<cnt<<endl;
		cnt=0;
	}
	
	return 0;
}

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

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1)
int b=a/1;
i+=a;
}
return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        n = 1000 - n;
        int ret = 0;
        for(int i=0; i<6; ++i){
            while(n >= coin[i]){
                n -= coin[i];
                ++ ret;
            }
        }
        cout << ret << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int coin[]={500,100,50,10,5,1};
	cin>>a;
	while(a!=0){
		a=1000-a;
		int total=0;
		int sheet=0;
		for(int i=0;i<6;i++){
			sheet=a/coin[i];
			a=a%coin[i];
			total+=sheet;
		}
		cout<<total<<endl;
		cin>>a;
	}
	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int N;

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

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

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