分钱单算法
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;
}
}
}

