分钱单算法

分钱单算法

1.有6个员工,每个人的工资是2000到5000不等,并且有零头;
【1】2104
【2】2320
【3】3450
【4】4520.1
【5】4876.3
【6】4995.9
2.财务发现金,现求出共要发多少现金,100元、50元、20元、10元、5元、2元、1元、5角、2角、1角分别为多少?(分不记)
3.规则要求,按大面额现金最优发放。

具体的算法:

using System;
using System.Collections.Generic;
using System.Text;

namespace 分钱单
{
class Program
{
//人民币民面额
static float[] 面额 = new float[] { 100f, 50f, 20f, 10f, 5f, 2f, 1f, 0.5f, 0.2f, 0.1f };

static void Main(string[] args)
{
float[] 工资单 = new float[] { 2104f, 2320f, 3450f, 4520.1f, 4876.3f, 4995.9f };
int[] 面额计数 = 分钱单计算(工资单);
float 总金额 = 总金额计算(工资单);

for (int i = 0; i < 面额计数.Length; i++)
Console.WriteLine("面额{0}元 共 {1}张", 面额[i], 面额计数[i]);
Console.WriteLine("共{0}元", 总金额);

Console.WriteLine("第一个人的工资:{0} ", 工资单[0]);
面额计数 = 分钱单计算(new float[] { 工资单[0] });
for (int i = 0; i < 面额计数.Length; i++)
Console.WriteLine("面额{0}元 共 {1}张", 面额[i], 面额计数[i]);

Console.ReadLine();
}

static int floatHelper(float f)
{
return int.Parse((f * 100).ToString());
}

static int[] 分钱单计算(float[] 金额)
{
int[] 面额计数器 = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

foreach (float tm in 金额)
{
int iTm = floatHelper(tm);
while (iTm > 0)
for (int i = 0; i < 面额.Length; i++)
if (iTm >= floatHelper(面额[i]))
{
iTm -= floatHelper(面额[i]);
面额计数器[i] += 1;
break;
}
}
return 面额计数器;
}

static float 总金额计算(float[] 金额)
{
float totalMoney = 0.00f;
foreach (float tm in 金额)
totalMoney += tm;
return totalMoney;
}
}
}




本文转自suifei博客园博客,原文链接:http://www.cnblogs.com/Chinasf/archive/2007/11/13/958409.html如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值