# 计算找零

<html>
<title>Insert title here</title>
<body>
<script language="JavaScript">
function money(){
facmoney = parseInt(document.form1.facmoney.value);
realmoney = parseInt(document.form1.realmoney.value);
money = facmoney - realmoney;
H = parseInt(money/100);
F = parseInt((money%100)/50);
E = parseInt(((money%100)%50)/20);
T = parseInt((((money%100)%50)%20)/10);
Fiv = parseInt(((((money%100)%50)%20)%10)/5);
Y = parseInt(((((money%100)%50)%20)%10)%5)/1;
document.form1.M.value = money;
document.form1.H.value = H;
document.form1.F.value = F;
document.form1.E.value = E;
document.form1.T.value = T;
document.form1.Fiv.value = Fiv;
document.form1.Y.value = Y;
}
</script>
<form name="form1">
实收金额:<input name="facmoney" type="text"><br>
应收金额:<input name="realmoney" type="text"><br>
<input type="button" value="计算" onclick="money()"><br><hr>
找零  ：     <input type="text" name="M">元<br>
100:<input type="text" name="H">张<br>
50:<input type="text" name="F">张<br>
20:<input type="text" name="E">张<br>
10:<input type="text" name="T">张<br>
5:<input type="text" name="Fiv">张<br>
1:<input type="text" name="Y">张<br>
</form>
</body>
</html>
<pre class="java" name="code"><%@page import="java.util.*" contentType="text/html; charset=gb2312" %>
<%!
Map<String,Integer> MoneyMap = new HashMap<String,Integer>();
private final int F=50;
private final int E=20;
private final int T=10;
private final int Fiv=5;
private final int Y=1;
int money,num=0;

private void CalMoney(int money) {
num = money/F;
MoneyMap.put(F+"元",num);
num = (money%F)/E;
MoneyMap.put(E+"元",num);
num = ((money%F)%E)/T;
MoneyMap.put(T+"元",num);
num = (((money%F)%E)%T)/Fiv;
MoneyMap.put(Fiv+"元",num);
num = ((((money%F)%E)%T)%Fiv)/1;
MoneyMap.put(Y+"元",num);

}
%>
<%
String realmoney = "";
realmoney = request.getParameter("money");
if(realmoney != null && !realmoney.equals(" ")){
try{
money = Integer.parseInt(realmoney);
CalMoney(money);
}catch(NumberFormatException e){
out.print("输入错误");
}
}
%>

<html>
<title>Money Number</title>
<body>
<%@ include file="test_Log.jsp" %>
<form name="form" action="test_test.jsp" method="post">
输入金额：<input type="text" name="money"><input type="submit" value="提交"><br>
<%
Set set = MoneyMap.keySet();
Iterator it = set.iterator();
for(; it.hasNext(); ){
String key = (String)it.next();
Integer value = MoneyMap.get(key);
out.print(key+" :");
out.print(value+"<br>");

}
%>
<%@ include file="test_Moneybottom.jsp" %>
</form>
</body>
</html>

#### 硬币找零问题（完全背包）

2016-02-25 11:07:09

#### 从自动贩卖机找零看Python中的动态规划问题

2017-10-08 23:10:37

#### 编写关于收银员的收银界面，显示购买个数，收银金额，找零金额的显示。

2016-09-20 11:39:51

#### jsp牛刀小试之在线报名系统

2015-05-28 15:22:42

#### JSP第一个实例之用户管理系统

2017-04-01 16:41:00

#### Hello JSP！——<jsp:param>动作元素篇

2015-09-05 12:27:56

#### 贪心算法解硬币找零问题

2015-03-02 22:00:01

#### 常见算法 - 硬币找零 &amp;&amp; 等和拆分数组

2018-05-27 21:35:20

#### nyoj995硬币找零（dp）

2015-04-07 17:45:10

#### 编程之美--------买票找零

2012-04-07 13:52:30