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++: 






 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe

































































 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe




















 


Beta 




 
 paiza.IO 


 ??°????????????  


?????§


???????????????


 ??\??¬???   






 
???????????¢?????? 

?????°?????? 

???  





 

























































 





C++   Split Button!   

   

 
 Main.cpp   ???  

 
+ 


 
 

 Success 



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47







        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){











 


??± ?????? (Ctrl-Enter)    Split Button!   












   ???     ???   ???   ??£   
   
 
???  
 

 
??? ??? ???   
 
???  
 ???    



 ?????? 








 ??\???  


 ???????????? 0  

(0.00 sec)  

 
TextHTMLJSON ???  


3
15
4















 








 



















 







































































  

SumoMe








































#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n = 1;
    int pay ;

    
    while (n){
        int cent = 0;
        
        cin >>n;
        if (n==0){
            break;
        }
    

    
    pay = 1000 - n;
    
    if (pay >= 500){
        pay -= 500;
        cent++;
    }
    
    while (pay >= 100){
        pay -= 100;
        cent++;
    }
    
    while (pay >= 50){
        pay -= 50;
        cent++;
    }
    
    while (pay >= 10){
        pay -= 10;
        cent++;
    }
    
    while (pay >= 5){
        pay -= 5;
        cent++;
    }
    
    while (pay >= 1){
        pay -= 1;
        cent++;
    }
    
    cout << cent << "\n";
 
    
    }
    return 0;

}

C++: #include<iostream>

using namespace std;

int main()
{
	int num, cnt;

	while(cin >> num)
	{
		if(!num) break;
		num = 1000 - num;
		cnt = 0;
		
		while(num)
		{
			if(num >= 500) num -= 500;
			else if(num >= 100) num -= 100;
			else if(num >= 50) num -= 50;
			else if(num >= 10) num -= 10;
			else if(num >= 5) num -= 5;
			else if(num >= 1) num -= 1;
			cnt++;
		}
		cout << cnt << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main() {

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

	while(cin >> n) {
		if(!n) {
			break;
		}
		int t=0;
		n=1000-n;
		int i=5;
		while(i!=-1) {
			if(n>=a[i]) {
				n-=a[i];
				t++;
			}
			else {
				i--;
			}
		}

		cout << t << endl;
	}

	return 0;

}

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

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

int main() {
	int a,b;
	cin >> a;
	b=1000-a;
	cout << 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 << endl;
	
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


int main(){

	int a[6]={500,100,50,10,5,1};
	int b,s;
	while(true){

	cin >> b;
	if(b==0) break;

	int coins=0;
	s=1000-b;
	rep(i,6){

	coins+=s/a[i]; s%=a[i];

	}

	cout << coins << endl;

	}

	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int coin=0;
	int price=0;
	int flag=0;
	cin>>price;
	while(1){
		if(flag==0){
			break;
		}
		if(price>=500){
			price=price-500;
			coin=coin+1;
		}
		else if(price>=100){
			price=price-100;
			coin=coin+1;
		}
		else if(price>=50){
			price=price-50;
			coin=coin+1 ;
		}
		else if(price>=10){
			price=price-10;
			coin=coin+1 ;
		}
		else if(price>=5){
			price=price-5;
			coin=coin+1 ;
		}
		else if(price>=1){
			price=price-1;
			coin=coin+1 ;
		}
		else if(price==0){
			flag=1;
		}
	}
	cout<<coin<<endl;

	return 0;

}

C++: #include <iostream>
//#include <fstream>
#include <vector>
#include <string>
//#include <cstdlib>
//#include <algorithm>
//#include <set>
//#include <conio.h>
using namespace std;
 
int main(){
	int n;
	while(cin >> n&& n!=0){
		int sum=0,pri=1000-n;
		while(pri>=500){
			pri -=500;
			++sum;
		}
		while(pri>=100){
			pri -=100;
			++sum;
		}
		while(pri>=50){
			pri -=50;
			++sum;
		}
		while(pri>=10){
			pri -=10;
			++sum;
		}
		while(pri>=5){
			pri -=5;
			++sum;
		}
		while(pri>=1){
			pri -=1;
			++sum;
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  n=1000-n;
  int a[]={500,100,50,10,5,1};
  int ans=0;
  for(int i=0;i<6;i++){
    while(n>=a[i]) n-=a[i],ans++;
  }
  cout<<ans<<endl;
  return 0;
}