作为企业的老板,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵
但是对于财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡最近就在考虑一个问题:
如果每个员工的工资额都知道,最少需要准备多少张人民币,才能在给每位员工发工资的时候都不用找零呢?
这里假设员工的工资都是正整数,单位元,人民币一共有100元、50元、10元、5元、2元和1元六种。
Input
输入数据包含多个测试实例,每个测试实例的第一行是一个整数n(n<100),表示员工的人数,然后是n个员工的工资。
n=0表示输入的结束,不做处理。
Output
对于每个测试实例输出一个整数x,表示至少需要准备的人民币张数。每个输出占一行。
Sample Input
3
1 2 3
0
Sample Output
4
public class FaGongZi {
public static void main(String[] args) {
String str="1 2 3 1578";
System.out.println(method(str));
}
public static int method(String str){
String[] strs=str.split(" ");
int count=0;
for(String s:strs){
count+=method2(Integer.parseInt(s));
}
return count;
}
public static int method2(int sal){
int count=0;
if(sal>=100){
while(sal>=100){
sal-=100;
count++;
}
}
if(sal>=50){
while(sal>=50){
sal-=50;
count++;
}
}
if(sal>=10){
while(sal>=10){
sal-=10;
count++;
}
}
if(sal>=5){
while(sal>=5){
sal-=5;
count++;
}
}
if(sal>=2){
while(sal>=2){
sal-=2;
count++;
}
}
if(sal>=1){
while(sal>=1){
sal-=1;
count++;
}
}
return count;
}
}