Allan
菜鸟也是有梦想的...

导航

 
工作已有一段时间了,突然想起了之前的一道面试题, 题目意思大概是这样的,有一份工资,根据人民币面额统计各个面额的数量。 下面是我写的一个实例: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace process { class AsynchronousExample { List statisticeArray = new List(); int[] arr = {1, 2, 5, 10, 20, 50, 100}; int time = 7; /// /// 计算出每单位的张数 /// /// /// public int tally(ref int amount) { int remainder =Convert.ToInt32(amount / arr[time-1]); amount = amount % arr[time - 1]; time--; return remainder; } /// ///把数量添加到数组中 /// /// public void statistics(int quantity) { statisticeArray.Add(quantity); } public static void Main(string[] args) { AsynchronousExample a = new AsynchronousExample(); int amount = 4523; while (a.time > 0) { a.statistics(a.tally(ref amount)); } Console.WriteLine("总额为4523的工作,含有"); for (int i = 0; i < a.arr.Length; i++) { Console.WriteLine("面额为{0}的为{1}张", a.arr[a.arr.Length - i - 1], a.statisticeArray[i]); } } } } 这个实例能简单地统计出整数的工资的货币面额的数量,但是不足的就是还没有做小数点后面的统计功能 假如你有更好的建议,不妨交流下,谢谢~ ----------------------------------------------------------------------- 分享快乐,翱翔之心 -----------------------------------------------------------------------
posted on 2011-07-26 23:55  AllanGuan  阅读(175)  评论(0)    收藏  举报