# 求算法(合并重叠时间段)

0

StartTime EndTime
06:10:58 08:15:28
07:38:56 10:34:45
10:55:00 11:34:00
13:09:34 17:45:23
14:23:12 15:24:14
16:14:25 17:52:15
...

StartTime EndTime
06:10:58 10:34:45
10:55:00 11:34:00
13:09:34 17:52:15
...

0

`public class bw22617    {        private List<Betime> timeList = new List<Betime>() {             new Betime{BeginTime=new DateTime(2011,3,1,6,10,58),EndTime=new DateTime(2011,3,1,8,15,28)},            new Betime{BeginTime=new DateTime(2011,3,1,7,38,56),EndTime=new DateTime(2011,3,1,10,34,45)},            new Betime{BeginTime=new DateTime(2011,3,1,10,55,0),EndTime=new DateTime(2011,3,1,11,34,0)},            new Betime{BeginTime=new DateTime(2011,3,1,13,9,34),EndTime=new DateTime(2011,3,1,17,45,23)},            new Betime{BeginTime=new DateTime(2011,3,1,14,23,12),EndTime=new DateTime(2011,3,1,15,24,14)},            new Betime{BeginTime=new DateTime(2011,3,1,16,14,25),EndTime=new DateTime(2011,3,1,17,52,15)}        };        public void Union()        {            for (int i = 0; i < timeList.Count-1;i++ )            {                int j=i+1;                if (timeList[i].EndTime >= timeList[j].BeginTime)                {                    if (timeList[i].EndTime >= timeList[j].EndTime)                    {                        timeList[j] = timeList[i];                    }                    else                    {                        timeList[j].BeginTime = timeList[i].BeginTime;                    }                    timeList[i] = null;                }                else                {                    i++;                }            }            timeList.ForEach(                delegate(Betime p)                {                    if (p != null)                    {                        Console.WriteLine("BeginTime: "+p.BeginTime+"\tEndTime: "+p.EndTime);                    }                }            );        }    }    public class Betime    {        public DateTime BeginTime { get; set; }        public DateTime EndTime { get; set; }    }`

artwl | 专家六级 |园豆：16736 | 2011-02-27 11:39

artwl | 园豆：16736 (专家六级) | 2011-03-01 14:59

0

您需要登录以后才能回答，未注册用户请先注册