1 /**
2 * 分钱单算法
3
4 1.有6个员工,每个人的工资是2000到5000不等,并且有零头;
5 【1】2104
6 【2】2320
7 【3】3450
8 【4】4520.1
9 【5】4876.3
10 【6】4995.9
11 2.财务发现金,现求出共要发多少现金,100元、50元、20元、10元、5元、2元、1元、5角、2角、1角分别为多少?(分不记)
12 3.规则要求,按大面额现金最优发放。
13 * */
14 class Program
15 {
16 static float[] salary = { 2104, 2320, 3450, 4520.1f, 4876.3f, 4995.9f };
17
18 static void Main(string[] args)
19 {
20
21 Dictionary<int, int> dispenseSalary = new Dictionary<int, int>();
22
23 dispenseSalary.Add(1000, 0);
24 dispenseSalary.Add(500, 0);
25 dispenseSalary.Add(200, 0);
26 dispenseSalary.Add(100, 0);
27 dispenseSalary.Add(50, 0);
28 dispenseSalary.Add(20, 0);
29 dispenseSalary.Add(10, 0);
30 dispenseSalary.Add(5, 0);
31 dispenseSalary.Add(2, 0);
32 dispenseSalary.Add(1, 0);
33
34 //利用求余的方法来做
35 salary.ToList().ForEach(s => {
36 int remainder = int.Parse((s * 10).ToString());
37 int count = 0;
38 Console.WriteLine("salay is {0}", s);
39 dispenseSalary.ToList().ForEach(w=>{
40 count = remainder / w.Key;
41 dispenseSalary[w.Key]+=count;
42 Console.WriteLine(InputHelper(w.Key,count));
43
44 remainder %= w.Key;
45
46 });
47 });
48 Console.WriteLine("The total salary is {0}", salary.Sum());
49 Console.WriteLine("The following is result we want. ");
50 dispenseSalary.ToList().ForEach(w => Console.WriteLine(InputHelper(w.Key,w.Value)));
51
52 Console.Read();
53 }
54
55 static string InputHelper(int money,int count)
56 {
57 int m=money/10;
58 return m >= 1 ? string.Format("{0}元的张数为{1}", m, count) : string.Format("{0}角的张数为{1}", money,count);
59 }
60 }