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 <algorithm>
using namespace std;
int main(){
	int n,m,a,b,c,d,e,f;
	cin>>n;
	m=1000-n;
	for(a=0;a<2;a++){
	    for(b=0;b<5;b++){
			for(c=0;c<2;c++){
				for(d=0;d<5;d++){
					for(e=0;e<2;e++){
						for(f=0;f<5;f++){
							if(a*500+b*100+c*50+d*10+e*5+f*1==m){
								cout<<a+b+c+d+e+f<<endl;
								break;
                            }
							}
						}
					}
				}
			}
	    }
	return 0;
	}

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

int main()
{
	//?????????
	int num1=0,num2=0,num3=0;
	int p1=0,p2=0,p3=0,p4=0,p5=0,p6=0;
	int u1=0,u2=0,u3=0,u4=0,u5=0,u6=0;
	
	cin>>num1;
	if(num1==0){
		return 0;
	}
	num2=1000-num1;
	p1=num2/500;
	u1=num2%500;
	p2=u1/100;
	u2=u1%100;
	p3=u2/50;
	u3=u2%50;
	p4=u3/10;
	u4=u3%10;
	p5=u4/5;
	u5=u4%5;
	p6=u5/1;
	u6=u5%1;
	num3=p1+p2+p3+p4+p5+p6;
	cout<<num3;
	cout<<"\n";
}

C++: #include <stdio.h>

void main(){
	int okane;
	int oturi;
	int count = 0;
	int a[] = { 1, 5, 10, 50, 100, 500 };

	scanf_s("%d", &okane);
	oturi = 1000 - okane;

	for (int i = 5; i >= 0; i--){
		if (okane >= a[i]){
			okane = okane - a[i];
			count = count + 1;
		}
	}
	printf("%d\n",count);

}

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

int main(int argc, char const *argv[])
{
	int n;
	while(cin>>n,n)
	{
		cin>>n;
		int c=1000-n,ans=0;
		while(c>=500) c-=500,++ans;
		while(c>=100) c-=100,++ans;
		while(c>=50) c-=50,++ans;
		while(c>=10) c-=10,++ans;
		while(c>=5) c-=5,++ans;
		while(c>=1) c-=1,++ans;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,c;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	c=0;
	n=1000-n;
	while(n>=500){
		n=n-500;
		c++;
	}
	while(n>=100){
		n=n-100;
		c++;
	}
	while(n>=50){
		n=n-50;
		c++;
	}	
	while(n>=10){
		n=n-10;
		c++;
	}
	while(n>=5){
		n=n-5;
		c++;
	}	
	while(n>=1){
		n=n-1;
		c++;
	}
	printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;

int main(){
	/*
	//数あて
	int n;
	cin >> n;
	int p[200][3];

	for(int i=0;i<n;i++)
	{
		cin >> p[i][0] >> p[i][1] >> p[i][2];
	}

	int _p;
	for(int k=0;k<3;k++)
	{
		for(int i=0;i<n;i++)
		{
			_p = p[i][k];
			for(int j=i+1;j<n;j++)
			{
				if(_p == p[j][k])
				{
					p[i][k] = 0;
					p[j][k] = 0;
				}
			}
		}
	}

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

	/*
	//得点
	int ai,am,as,ae,bi,bm,bs,be;
	cin >> ai >> am >> as >> ae >> bi >> bm >> bs >> be;
	int answer=ai+am+as+ae;
	if(answer < bi+bm+bs+be)
	{
		answer=bi+bm+bs+be;
	}
	cout << answer << endl;
	*/

	//おつり
	int onum[5];
	int i = 0;
	while(true){
		int N;
		cin >> N;
		if(N == 0) break;
				
		int oturi = 1000-N;
		if(oturi >= 500)
		{
			onum[i]++;
			oturi -= 500;
		}
		while(oturi>=100)
		{
			onum[i]++;
			oturi -= 100;
		}
		if(oturi >= 50)
		{
			onum[i]++;
			oturi -= 50;
		}
		while(oturi>=10)
		{
			onum[i]++;
			oturi -= 10;
		}
		if(oturi >= 5)
		{
			onum[i]++;
			oturi -= 5;
		}
		while(oturi>=1)
		{
			onum[i]++;
			oturi -= 1;
		}
		
		i++;
	}
    cout << onum[0] << onum[1] << onum[2] << onum[3] << onum[4] << endl;
	return 0;
}

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

int main(void)
{
	int much;

	while(cin >> much, much > 0){
		int c = 0;

		much = 1000 - much;

		if(much >= 500){
			c += (int)(much / 500);
			much %= 500;
		}
		if(much >= 100){
			c += (int)(much / 100);
			much %= 100;
		}
		if(much >= 50){
			c += (int)(much / 50);
			much %= 50;
		}
		if(much >= 10){
			c += (int)(much / 10);
			much %= 10;
		}
		if(much >= 5){
			c += (int)(much / 5);
			much %= 5;
		}
		c += much;

		cout << c << endl;

	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
constexpr int c[] = { 500, 100, 50, 10, 5, 1 };

int main() {
  int a;
  while (cin >> a, a) {
    int b = 1000 - a;
    int ans = 0;
    for (int i = 0; i < 6; i++) {
      ans += b / c[i];
      b %= c[i];
    }
    cout << ans << "\n";
  }
}

C++: #include <iostream>

using namespace std;

int main() {
  while (true) {
    int M;
    cin >> M;
    if (M == 0) {
      break;
    }
    int m = 1000 - M;

    int ans = 0;
    while (m > 0) {
      if (m >= 500) {
        m -= 500;
      } else if (m >= 100) {
        m -= 100;
      } else if (m >= 50) {
        m -= 50;
      } else if (m >= 10) {
        m -= 10;
      } else if (m >= 5) {
        m -= 5;
      } else {
        m--;
      }

      ans++;
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include <cstdio>

int main() {
	
	while(1){
		int num,n=0,i=0,a=0,b=0;
		scanf("%d",&num);
		if(num==0) break;
		n=1000-num;

	if (n>=500) {
		i++;
		n=(n-500);
	}
	if (n>=100){
		a=n/100;
		i=a+i;
		n=n%100;
	}
	if (n>=51){
		i++;
		n=(n-50);
	}
	if (n>=11){
		b=n/10;
		i=b+i;
		n=n%10;
	}
	if (n>=6){
		i++;
		n=(n-5);
	}
		i=(i+n);
	printf("%d\n",i);
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	// Dynamic Programming
	// dp[àz] = Å¬

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

	int n;
	while ( cin >> n && n )
	{
		vector <int> dp( (1000-n)+1, 0 );
		for ( int i = 0; i < 6; i++ ) dp[coins[i]] = 1;

		for ( int i = 0; i < (1000-n)+1; i++ )
		{
			if ( dp[i] > 0 )
			{
				for ( int j = 0; j < 6; j++ )
				{
					if ( i + coins[j] < (1000-n)+1 )
					{
						if ( dp[i+coins[j]] == 0 ) dp[i+coins[j]] = dp[i] + 1;
						else dp[i+coins[j]] = min( dp[i+coins[j]], dp[i] + 1 );
					}
				}
			}
		}

		cout << dp[(1000-n)] << endl;
	}

	return 0;
}

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

int main()
{
  int n;
  while(cin >> n, n){
    int cnt = 0, co[6] = {500, 100, 50, 10, 5, 1};
    n = 1000 - n;

    for (int i = 0; i < 6; i++){
      int a = n / co[i];
      cnt += a;
      n -= a * co[i];
    }

    cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i,cost,coin;
    cin>>cost;
    while(cost!=0){
        cost=1000-cost;
        coin+=cost/500;
        cost%=500;
        coin+=cost/100;
        cost%=100;
        coin+=cost/50;
        cost%=50;
        coin+=cost/10;
        cost%=10;
        coin+=cost/5;
        cout<<coin<<endl;
        cin>>cost;
    }
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int score;
int use(int money, int coin){
	int ans = money / coin;
	score += ans;
	return ans;
}

int main(){
	int money;
	scanf("%d", &money);
	money = 1000 - money;
	money -= use(money, 500) * 500;
	money -= use(money, 100) * 100;
	money -= use(money, 50) * 50;
	money -= use(money, 10) * 10;
	money -= use(money, 5) * 5;
	money -= use(money, 1) * 1;
	printf("%d\n", score);
	return 0;
}

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

C++: #include<cstdio>
int ks[6]={500,100,50,10,5,1};
int main(){
    for(;;){
        int ins;
        scanf("%d",&ins);
        if(ins==0)break;
        ins=1000-ins;
        int ans=0;
        for(int i=0;i<6;i++){
            ans+=ins/ks[i];
            ins-=ks[i]*(ins/ks[i]);
        }
        printf("%d\n",ans);
    }
}