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 <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	int d;
	int e;
	int f;
	int g;
	int h;
	int i;
	int j;
	while (1)
	{
		cin >> a;
		if (a = 0)
		{
			break;
		}
		b = a;
		if (b >= 500)
		{
			b = b - 500;
			c++;
		}
		if (b >= 100)
		{
			b = b - 100;
			c++;
		}
		if (b >= 50)
		{
			b = b - 50;
			c++;
		}
		if (b >= 10)
		{
			b = b - 10;
			c++;
		}
		if (b >= 5)
		{
			b = b - 5;
			c++;
		}
		if (b >= 1)
		{
			b = b - 1;
			c++;
		}
		cout << c << endl;
	}
	return 0;
}

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

int main(){
	int a,b,c,d1,e,f,g,h;
	int sum=0;
	while(cin>>a){
		if(a==0)break;
		b=1000-a;
		c=b/500;
		d=(b-500*c)/100;
		e=(b-500*c-100*d)/50;
		f=(b-500*c-100*d-50*e)/10;
		g=(b-500*c-100*d-50*e-10*f)/5;
		h=b-500*c-100*d-50*e-10*f-5*g;
		cout<<c+d+e+f+g+h<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	while (1) {
		int ki, co = 0;
		cin >> ki;
		if (ki == 0) { break; }
		ki = 1000 - ki;
		if (ki >= 500) {
			ki = ki - 500;
			co++;
		}
		if (ki >= 100) {
			for (int i = 0; ki < 100; i++) {
				ki = ki - 100;
				co++;
			}
		}
		if (ki >= 50) {
			ki = ki - 50;
			co++;
		}
		if (ki >= 10) {
			for (int i = 0; ki < 10; i++) {
				ki = ki - 10;
				co++;
			}
		}
		if (ki >= 5) {
			ki = ki - 5;
			co++;
		}
		if (ki >= 1) {
			for (int i = 0; ki == 0; i++) {
				ki = ki - 1;
				co++;
			}
		}
		cout << co << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(void){
  int n,cha,count=0;

  while(1){

    scanf("%d",&n);
    if(n == 0) break;

    cha=1000-n;

    if(cha >= 500){
      cha -= 500;
      count++;
    }

    while(cha >= 100){
      cha -= 100;
      count++;
    }

    if(cha >= 50){
      cha -= 50;
      count++;
    }

    while(cha >= 10){
      cha -= 10;
      count++;
    }

    if(cha >= 5){
      cha -= 5;
      count++;
    }

    while(cha >= 1){
      cha -= 1;
      count++;
    }

    printf("%d\n",count);

  }
  return 0;
}

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

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

}

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

 
int main () 
{
  int m1;
  while(1)
  {
   cin>>m1; 
   if(m1>0||m1<=1000)
   {
       break;
   }
   else
    {
    int m2,m3,m4,m5,m6,m7;

   m2=1000-m1;
   m3=m2/500;
   m4=m2%500/100;
   m5=m2%500%100/50;
   m6=m2%500%100%50/10;
   m7=m2%500%100%50%10/1;
  
   cout<<m3+m4+m5+m6+m7<<'\n';
   }
 }
   
  return 0;
}

C++: #include<stdio.h>
int main()
{
	int cnt = 0, a, b, i, j;
	while(1){
	scanf("%d", &a);
	cnt = 0;
		if (a == 0) {
			break;
		}
		while (1) {
			if (a >= 500) {
				a = a - 500;
				cnt++;
			}
			else if (a >= 100) {
				a = a - 100;
				cnt++;
			}
			else if (a >= 50) {
				a = a - 50;
				cnt++;
			}
			else if (a >= 10) {
				a = a - 10;
				cnt++;
			}
			else if (a >= 1) {
				a = a - 1;
			}
			if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>

#define _USE_MATH_DEFINES
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define atcoder 1000000007
#define MAX_N 100

using namespace std;

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

int main() {

	int n,ans = 0;

	while (cin >> n, n) {
		n = 1000 - n;
		REP(i, 6) {
			int m = n / V[i];
			n -= V[i] * m;
			ans += m;
		}
		cout << ans << endl;
		ans = 0;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int a,b;
  int count;
  while(1){
    count = 0;
    cin >> a;
    if( a == 0) break;

    b = 1000 - a;
    a = b%500;
    count = count + b/500;

    b= a%100;
    count = count + a/100;

    a = b%50;
    count = count + b/50;

    b = a%10;
    count = count + a/10;

    a = b%5;
    count = count + b/5;

    b = a%1;
    count = count + a/1;

    cout << count <<endl;

  }
  return 0;
}

C++: //============================================================================
// Name        : oturi.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int pay = 1000,buy,oturi = 0,gohyaku,gohyakua,hyaku,hyakua,goju,gojua,ju,jua,go,goa;
    while(1){
	cin >> buy;
	if(buy == 0){
		break;
	}
	oturi = pay - buy;
	gohyakua = oturi % 500;
	gohyaku = oturi / 500;
	hyakua = gohyakua % 100;
	hyaku = gohyakua / 100;
	gojua = hyakua % 50;
	goju = hyakua / 50;
	jua = gojua % 10;
	ju = gojua / 10;
	goa = jua % 5;
	go = jua / 5;
	cout << gohyaku + hyaku + goju + ju + go + goa << endl;
    }
	return 0;
}

C++: #include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	int a,b=0,c=0;
	cin>>a;
	b=1000-a;
	c=(b/500)+((b%500)/100)+(((b%500)%100)/50)+((((b%500)%100)%50)/10)+(((((b%500)%100)%50)%10)/5)+(((((b%500)%100)%50)%10)%5);
	cout<<c<<endl;
	return 0;
}

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

  n = 1000-n;
  // 996  = 500 + 4*100 + 1 * 50 + 4*10 + 1*5 + 1
  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<cstdio>

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

	while(1){
		scanf("%d",&money);
		if(money == 0)break;
		int fishing = 1000-money;
		int cnt = 0;
		
		for(int i=0;i<6;++i){
			if(fishing < 0)break;
			int tmp = fishing/dat[i];
			fishing -= tmp * dat[i];
			cnt += tmp;
		}

		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num = 0;
	
	while (scanf("%d", &price), price){
		scanf("%d", &price);
		back = PAY - price;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d", num);
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,a,b,x,y,z,m,i,c;
	scanf("%d",&n);
	a=1000-n;
	b=a/500;
	x=a%500;
	y=x/100;
	z=x%100;
	m=z/10;
	i=z%10;
	c=b+y+m;
	printf("%d\n",c);
	return 0;
}