平均分配算法

做CallCenter项目时经常遇到的客户资料平均分配问题,很简单的算法,整理一下

using System; using System.Collections.Generic; namespace Test { class Program { static List listCus = new List(); static List peasons = new List(); static Dictionary> result = new Dictionary>(); static void Main(string[] args) { #region 初始化数据 int m = 4230; int n = 50; for (int i = 0; i < m; i++) { listCus.Add(i); } Console.WriteLine("分配结果:"); for (int j = 0; j < n; j++) { string t = (j+1).ToString().PadLeft(12, '0'); peasons.Add(t); result.Add(t, new List()); } #endregion #region 算法部分 int iAv = m / n; int iMod = m % n; int it = 0 ; int ll = 0 ; foreach (string k in result.Keys) { ll = iMod > 0 ? 1 : 0; result[k].AddRange(listCus.GetRange(it, iAv + ll)); it += iAv; --iMod; Console.WriteLine("{0}:{1}",k,result[k].Count); } #endregion } } }

你可能感兴趣的:(Visual,C#)