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






 


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>
#define shiharai 1000
using namespace std;
int main(){
    while(1){
        const int Zeni[6] = {500,100,50,10,5,1};
        int daikin = 0;
        int otsuri = 0;
        int Ozeni = 0;
        int i = 0;
        cin >> daikin;
        if(daikin == 0){
            break;
        }
        otsuri = shiharai - daikin;
        while(i < 6){
            while(otsuri >= Zeni[i]){
                Ozeni++;
                otsuri-=Zeni[i];
            }
            i++;
        }
        cout << Ozeni << endl;
    }
    return 0;
}

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

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

int kouka[6] = { 500,100,50,10,5,1 };
int main() {
	int a;
	while (cin >> a, a) {
		a = 1000 - a;
		int sum = 0;
		for (int b = 0; b < 6; b++) {
			sum += a / kouka[b];
			a -= a / kouka[b] * kouka[b];
		}
		cout << sum << endl;
	}
}

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

int main() {
while(1){
int n,a,i=0;
cin>>n;
if(n==0)
break;
a=1000-n;
if(a>=500){
i+=1;
a-=500;
}
if(a>=100){
int b=a/100;
i+=b;
a-=100*b;
}
if(a>=50){
i+=1;
a-=50;
}
if(a>=10){
int b=a/10;
i+=b;
a-=10*b;
}
if(a>=5){
i+=1;
a-=5;
}
if(a>=1)
int b=a/1;
i+=a;
}
return 0;
}

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

int main()
{
int value, coins = 0;
while(true){
cin >> value;
if(value == 0) break;
value = 1000-value;
coins += value/500; value%=500;
coins += value/100; value%=100;
coins += value/50; value%=50;
coins += value/10; value%=10;
coins += value/5; value%=5;
coins += value;
cout << coins;
}
return 0;
}

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

int main() 
{ 
 int buy,oturi,kozeni,a,b,c,d,e,f; 
 while(1){
  cin>>buy;
  if(buy==0)
   break;
  else{
   oturi=1000-buy;
   a=oturi/500;
   if(a)b=(oturi-500)/100;
     else b=oturi/100;
   c=oturi%100/50;
   if(c)d=(oturi%100-50)/10;
     else d=oturi%100/10;
   e=oturi%10/5;
   if(e)f=oturi%10-5;
      else f=oturi%10;   

   kozeni=a+b+c+d+e+f;
   cout<<kozeni<<"\n";
  }
 }
 return 0; 
}