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 <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 105
using namespace std;
bool debug=false;

bool check(int n){
  int k=0,x=n;
  while(x){
    k++;
    x/=10;
  }
  if(k==1){
    return true;
  }else if(k==2){
    if(n%10==n/10)return true;
  }else if(k==3){
    if(n%10==n/100)return true;
  }else if(k==4){
    if((n%10==n/1000)&&(n/10%10==n/100%10))return true;
  }
  return false;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<1000;i++){
    if(check(n-i)&&n-i>0){
      cout<<n-i<<endl;
      return 0;
    }
    if(check(n+i)&&n<10000){
      cout<<n+i<<endl;
      return 0;
    }
  }
  return 0;
}

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

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

int main(){
int s;
int a[]={500,100,50,10,5,1};
int b;
while(scanf("%d",&b),b){
	s=0;
	int c=1000-b;
	for(int d=0;d<6;d++){
		int e=c/a[d];
		s+=e;
		c-=e*a[d];
	}
	printf("%d\n",s);
}
}

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

int main(int argc, const char * argv[]) {
    
    int nyuuryoku[5];
    int oturi[5];
    int maisuu[5];
    int data;
    
    for(int i=0;i<5;i++){
        maisuu[i]=0;
    }
    
    for(int i=0;;i++){
        cin >> nyuuryoku[i];
        if(nyuuryoku[i]==0){
            data=i;
            break;
        }
    }
    
    
    for(int i=0;i<data;i++){
        oturi[i]=1000-nyuuryoku[i];
    }
    
    
    for(int i=0;i<data;i++){
        
        for(;;){  //500???
            if(oturi[i]<500){
                break;
            }
            oturi[i]=oturi[i]-500;
            maisuu[i]++;
        }
        
        for(;;){  //100???
            if(oturi[i]<100){
                break;
            }
            oturi[i]=oturi[i]-100;
            maisuu[i]++;
        }
        
        
        for(;;){  //50???
            if(oturi[i]<50){
                break;
            }
            oturi[i]=oturi[i]-50;
            maisuu[i]++;
        }
        
        
        for(;;){  //10???
            if(oturi[i]<10){
                break;
            }
            oturi[i]=oturi[i]-10;
            maisuu[i]++;
        }
        
        
        for(;;){  //5???
            if(oturi[i]<5){
                break;
            }
            oturi[i]=oturi[i]-5;
            maisuu[i]++;
        }
        
        
        for(;;){  //1???
            if(oturi[i]<1){
                break;
            }
            oturi[i]=oturi[i]-1;
            maisuu[i]++;
        }
        
    }
    
    
    
    for(int i=0;i<data;i++){
        cout << maisuu[i] << endl;
    }
    
    
    return 0;
}