zoukankan      html  css  js  c++  java
  • 将M个客服随机分配给N个客户

    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; }
        }
  • 相关阅读:
    mysql 优化
    对象的特征
    对象的回收机制
    对象产生的过程
    python 内容查询小助手
    python笔记
    python安装MySQLdb模块
    python笔记
    python笔记
    定期删除备份文件,节省磁盘空间脚本
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/8352829.html
Copyright © 2011-2022 走看看