Go: package main

import "fmt"

func main() {
	var n, coins, change int
	for {
		fmt.Scan(&n)
		if n == 0 {
			return
		}
		coins = 0
		change = 1000 - n
		for change > 0 {
			coins++
			switch {
			case change >= 500:
				change -= 500
			case change < 500 && change >= 100:
				change -= 100
			case change < 100 && change >= 50:
				change -= 50
			case change < 50 && change >= 10:
				change -= 10
			case change < 10 && change >= 5:
				change -= 5
			default:
				change--
			}
		}
		fmt.Println(coins)
	}
}

C++: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    vector<int> bills = {500, 100, 50, 10, 5, 1};
    int n;
    while(cin >> n and n) {
        int change = 1000 - n;
        int ans = 0;
        for(int bill : bills) {
            while(change >= bill) {
                change -= bill;
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		n = 1000 - n;
		int ans = 0, i;
		int w[6] = { 500,100,50,10,5,1 };
		for (i = 0; i <= 5; i++) {
			ans = ans + n / w[i];
			n = n - n / w[i] * w[i];
		}
		cout << ans << endl;
	}
	return 0;
}

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


int main() {
	int coin[6]={500,100,50,10,5,1},price,sum;
	while (true)
	{
	    scanf("%d",&price);
		if (price == 0) break;
		sum =0;
		price = 1000-price;
		for (int i = 0; i <= 5; i++)
		{
				while (price>=coin[i]) {
					price-=coin[i];
					sum++;
				}



		}
		printf("%d\n", sum);
	}




	
	return 0;
}

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

	int m, count;

	cin >> m;

	while (m != 0){
		count = 0;
		m = 1000 - m;
		if (m >= 500){
			count += m / 500;
			m /= 500;
		}
		if (m >=100){
			count += m / 100;
			m /= 100;
		}if (m >= 50){
			count += m / 50;
			m /= 500;
		}if (m >= 10){
			count += m / 10;
			m /= 50;
		}if (m >= 5){
			count += m / 5;
			m /= 5;
		}
		count += m;

		cout << count << endl;

		cin >> m;
	}

}

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;
}