zoukankan      html  css  js  c++  java
  • Java发工资

    作为企业的老板,最盼望的日子就是每月的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;
    	}
    }
    
  • 相关阅读:
    Spring Data JPA条件查询
    Cannot add foreign key constraint
    项目运行慢的原因剖析
    文本摘要的一些研究概念
    datatables表格设置序号自增
    记录一次没有报错的错误
    final、static、this、super关键字总结
    datatables条件搜索后表格内出现重复字符串
    linux上重装redis,设置密码
    datatables render出现重复的字符
  • 原文地址:https://www.cnblogs.com/zyn0216/p/8023388.html
Copyright © 2011-2022 走看看