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 <bits/stdc++.h>
using namespace std;

int main()
{
	int v[] = {500, 100, 50, 10, 5, 1};
	while (1){
		int price;
		cin >> price;
		if (price == 0) return 0;
		price = 1000 - price;
		int ans = 0;

		for (int i = 0; i < 6; i++){
			ans += price / v[i];
			price %= v[i];
		}
		cout << ans << endl;
	}

}

C++: #include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int m,o,ans;
    while(1){
    o=0;
    ans=0;
    cin >> m;
    if(m==0)break;
    o=1000-m;
    if(o>500){
        o-=500;
        ans++;
    }
    if(o / 100 > 0){
        ans+=o/100;
        o%=100;
    }
    if(o>50){
        o-=50;
        ans++;
    }
    if(o / 10 > 0){
    ans+=o/10;
    o%=10;
    }
    if(o>5){
        ans++;
        o-=5;
    }
    ans+=o;
    cout <<ans<<endl;
    }
    return 0;
}

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

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

    while (scanf("%d", &n)) {
      if (!n) return 0;
      int sum = 0;
      n = 1000 - n;
      for (int i = 0; i < 6; i++) {
        sum += (n / coin[i]);
        n %= coin[i];
        if (!n) break;
      }
      cout << sum << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	while(cin >> n, n) {
		n = 1000 - n;
		int r = 0;
		r += n / 500; n %= 500;
		r += n / 100; n %= 100;
		r += n / 50; n %= 50;
		r += n / 10; n %= 10;
		r += n / 5; n %= 5;
		r += n;
		cout << r << endl;
	}
	return 0;
}

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


int main(){
  int much;
  int ot=0;
  cin>>much;
  much=1000-much;
  while(true){
    if(much>=500){
      much=much-500;
      ot=ot+1;
    }else{
      break;
    }
  }
  while(true){
    if(much>=100){
      much=much-100;
      ot=ot+1;
    }else{
      break;
    }
  }
  while(true){
    if(much>=50){
      much=much-50;
      ot=ot+1;
    }else{
      break;
    }
  }
  while(true){
    if(much>=10){
      much=much-10;
      ot=ot+1;
    }else{
      break;
    }
  }
  while(true){
    if(much>=5){
      much=much-5;
      ot=ot+1;
    }else{
      break;
    }
  }
  while(true){
    if(much>=1){
      much=much-1;
      ot=ot+1;
    }else{
      break;
    }
  }
  cout<<ot<<endl;

return 0;
}

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

int main(void){
	int n;
	while(cin >> n){
		int currency[]={500,100,50,10,5,1};
		int count = 0;
		int pay = 1000 - n;
		if(n==0) break;
		for(int i=0;i<6;++i){
			if(pay/currency[i]>0) count+=pay/currency[i];
			pay%=currency[i];
		}
		cout << count << "\n";
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){

    while(true){
        int s, o, i;
        int a, b, c, d, e, f;
        
        cin >> s;
        if(s == 0){
            break;
        }
        
        o = 1000 - s;
        
        a = o / 500;
        b = (o - 500*a ) / 100;
        c = (o - 500*a - 100*b) / 50;
        d = (o - 500*a - 100*b - 50*c) / 10;
        e = (o - 500*a - 100*b - 50*c - 10* d) / 5;
        f = o - 500*a - 100*b - 50*c - 10* d - 5*e;
        
        i = a + b + c + d + e + f;
        
        cout << i << endl;
    }
}

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

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int n,cnt=0;
        cin>>n;
        if(n==0){
            return 0;
        }
        n=1000-n;
        if(n>=500){
            cnt+=n/500;
            n%=500;
        }
        if(n>=100){
            cnt+=n/100;
            n%=100;
        }
        if(n>=50){
            cnt+=n/50;
            n%=50;
        }
        if(n>=10){
            cnt+=n/10;
            n%=10;
        }
        if(n>=5){
            cnt+=n/5;
            n%=5;
        }
        if(n>=1){
            cnt+=n/1;
            n%=1;
        }
        cout<<cnt<<endl;
    }
}

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

int main(){
  int kane;
  int a,i;
  
  while(1){
    a=0;
    cin >> kane;
    if(kane == 0)break;
    kane=1000-kane;
    
    if(kane >= 500){
      kane-=500;
      a++;
    }
    if(kane >= 100){
      i = kane/100;
      a+=i;
      kane-=100*i;
    }
    if(kane >= 50){
      i = kane/50;
      a+=i;
      kane-=50*i;
    }
    if(kane >= 10){
      i = kane/10;
      a+=i;
      kane-=10*i;
    }
    if(kane >= 5){
      i = kane/5;
      a+=i;
      kane-=5*i;
    }
    if(kane != 0){
      a+=kane;
    }
    cout << a <<endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
    int x, y;

    while(1) {
        scanf("%d", &x);
        if(x == 0) break;
        y = 1000-x;
        int cnt[6] = {0};
    
        while(y > 0) {
            if(y >= 500) {
                y -= 500;
                cnt[0]++;
            } else if(y >= 100) {
                y -= 100;
                cnt[1]++;
            } else if(y >= 50) {
                y -= 50;
                cnt[2]++;
            } else if(y >= 10) {
                y -= 10;
                cnt[3]++;
            } else if(y >= 5) {
                y -= 5;
                cnt[4]++;
            } else if(y >= 1) {
                y -= 1;
                cnt[5]++;
            } else {
                break;
            }
        }
    
        printf("%d\n", cnt[0]+cnt[1]+cnt[2]+cnt[3]+cnt[4]+cnt[5]);
    }

    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;
				cnt++;
			}
			else if (a == 0) {
				break;
			}
		}
		printf("%d\n", cnt);
	}
}

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

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    vector<int> pays;
    while (1) {
        int tmp;
        cin >> tmp;
        if (tmp == 0) {
            break;
        } else {
            pays.push_back(tmp);
        }
    }

    vector<int> coins = {500, 100, 50, 10, 5, 1};
    for (auto pay : pays) {
        int back = 1000 - pay; // お釣り
        int ans = 0;
        for (auto coin : coins) {
            int use = back / coin; // coin円 を使用する枚数
            back -= coin * use;
            ans += use;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
while(cin >> a){
if(n!=0){b=1000-a;
c=0;
if(b=>500){b=b-500; c=c+1;}
if(b=>100){while(b<100){b=b-100; c=c+1;}}
if(b=>50){b=b-50; c=c+1;}
if(b=>10){while(b<10){b=b-10; c=c+1;}}
if(b=>5){b=b-5; c=c+1;}
c=b+c;
cout << c<<endl;
}
}
}