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>
using namespace std;
int main(){
	int n,m;
	cin >> n;
	m = 0;
	n = 1000-n;

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

	cout << m << endl;

}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int m;
  while(cin>>m,m){
  int co=0;
  int o=1000-m;
  if(o>500){co++;o-=500;}
  while(o>=100){co++;o-=100;}
  while(o>=50){co++;o-=50;}
  while(o>=10){co++;o-=10;}
  while(o>=5){co++;o-=5;}
  while(o>=1){co++;o--;}

  cout<<co<<endl;
  }
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

  while(1) {
    cin >> money;
    if(!money) break;

    change = 1000-money;

    int cnt = 0;
    REP(i, 6) {
      while(change/coin[i] > 0) {	
	cnt++;
	change -= coin[i];
      }
    }
    cout << cnt << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    int x,y,a,b,c,d,e,f;
    while (true){
    cin >> x;
    if(x==0){
        break;
    }
    a=(1000-x)/500;
    b=(1000-x-500*a)/100;
    c=(1000-x-500*a-100*b)/50;
    d=(1000-x-500*a-100*b-50*c)/10;
    e=(1000-x-500*a-100*b-50*c-10*d)/5;
    f=1000-x-500*a-100*b-50*c-10*d-5*e;
    y=a+b+c+d+e+f;
    

    
        cout <<y <<endl;
    }
    
}

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

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

int main(void){
	int mon, cnt;
	while(true){
		cin >> mon;
		if(mon == 0)	break;
		mon = 1000 - mon;
		cnt = 0;
		for(int i = 0; i < 6; i++){
			if(mon == 0)	break;
			cnt += mon / change[i];
			mon -= change[i] * (mon / change[i]);
		}
		cout << cnt << endl;
	}
  return 0;
}

C++: #include <iostream>
using namespace std;
int coin[6] = {500,100,50,10,5,1};

int main() {
  int price,change,res=0;
  while(cin >> price) {
    if(price == 0) break;
    change = 1000 - price;
    for(int i=0;i<6;i++) {
      res += change/coin[i];
      change -= (change/coin[i]) * coin[i];
    }
    cout << res << endl;
    res = 0;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
	int a;
	int i;
	int s=0;
	
	while(cin>>a){
		if(a==0)break;
		s=0;
		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;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int m;
int cal(int a)
{
	int k=m/a;
	m-=a*k;
	return k;
}
int main()
{
	while(1)
	{
		int n;
		cin >> n;
		if(n==0)break;
		m=1000-n;
		int ans=0;
		ans+=cal(500);
		ans+=cal(100);
		ans+=cal(50);
		ans+=cal(10);
		ans+=cal(5);
		ans+=cal(1);
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value%500; value/=500;
coins += value%100; value/=100;
coins += value%50; value/=50;
coins += value%10; value/=10;
coins += value%5; value/=5;
coins += value;
cout << coins;
}
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 <cstdio>
using namespace std;
int main()
{while(1){
 int a;
 scanf("%d",&a);
if(a==0) return 0;
 a=1000-a;
 printf("%d\n",a/500a+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);}
}

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

int main(){
  int mon;
  while(cin >> mon,mon){
    int sum = 0;
    mon = 1000 - mon;
    sum += mon / 500;
    mon %= 500;
    
    sum += mon / 100;
    mon %= 100;
    
    sum += mon / 50;
    mon %= 50;
    
    sum += mon / 10;
    mon %= 10;
    
    sum += mon / 5;
    mon %= 5;
    
    cout << sum + mon << endl;
  }
}