首页 > 其他 > 详细

将M个客服随机分配给N个客户

时间:2018-01-25 19:42:15      阅读:249      评论:0      收藏:0      [点我收藏+]
class AllocUser
    {
        //客户多于客服
        public static void Test()
        {
            var customers = new List<Customer>()
            {
                new Customer()
                {
                    Name = "A"
                },
                new Customer()
                {
                    Name = "B"
                },
                new Customer()
                {
                    Name = "C"
                },
                new Customer()
                {
                    Name = "D"
                },
                new Customer()
                {
                    Name = "E"
                },
                new Customer()
                {
                    Name = "F"
                },  
                new Customer()
                {
                    Name = "G"
                },
            };

            var waiters = new List<Waiter>()
            {
                new Waiter()
                {
                    Name = "1"
                },
                new Waiter()
                {
                    Name = "2"
                },
                new Waiter()
                {
                    Name = "3"
                },
            };

            Alloc(customers, waiters.OrderBy(p => Guid.NewGuid()).ToList());
        }

        private static void Alloc(List<Customer> customers, List<Waiter> waiters)
        {
            for (int i = 0; i < customers.Count; i++)
            {
                var customer = customers[i];
                if (i < waiters.Count)
                {
                    customer.WaiterName = waiters[i].Name;
                }
                else
                {
                    customer.WaiterName = waiters[(i % waiters.Count)].Name;
                }

                System.Console.WriteLine(customer.ToString());
            }
        }
    }

    class Customer
    {
        public string Name { get; set; }
        public string WaiterName { get; set; }
        public override string ToString()
        {
            return string.Format("客户{0}被分配客服{1}", Name, WaiterName);
        }
    }

    class Waiter
    {
        public string Name { get; set; }
    }

 

将M个客服随机分配给N个客户

原文:https://www.cnblogs.com/zhshlimi/p/8352829.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!