致力于顾问预约系统。在线预订了许多临时约会,没有指定访问时间,但是持续时间。然而,顾问将于周六和周日上午9点至下午1点至下午2点至下午5点访问客户。
在线临时请求将指定原因和持续时间。我需要编写一个代码来安排这些请求,因此顾问可以登录并查看预定的项目并将其发送给客户
约翰离婚问题60分钟问题是如果我发现超过午餐的任何请求持续时间, 我需要忽略循环并检查下一个请求与小 持续时间。我不知道我怎么能暂时跳过并接下来处理 时间(中午时间表)。
库马尔土地发行100分钟
与Ram讨论60分钟
犯罪案件45min
本地结算15分钟
在下面的代码中我需要跳过犯罪案件,因为它超过午餐时间并安排本地结算。 我还需要在午餐后安排犯罪案件。我该怎么做?
public class OnlineRequest
{
public string Reason { get; set; }
public short Duration { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
public static string LUNCH_TIME = "1:00 P.M";
public static string END_OF_DAY = "6:00 P.M";
public static Dictionary<String, List<String>>
GetSchedules(List<OnlineRequest> requests)
{
List<string> schedules = new List<string>();
DateTime visitStartTime = DateTime.MinValue.Date.AddHours(9);
int day = 1;
List<String> eventTimeStr = new List<String>();
Dictionary<String, List<String>> consultantData
= new Dictionary<String, List<String>>();
//Here is the problem
DateTime eventTime = visitStartTime;
foreach (OnlineRequest req in requests)
{
req.StartTime = eventTime;
string flag = getTimeDiff(req);
if (flag.Equals(LUNCH_TIME))
{
eventTimeStr.Add(flag + ": LUNCH");
eventTime = eventTime.AddMinutes(60);
}
else if (flag.Equals(END_OF_DAY))
{
eventTimeStr.Add(flag + ": GO HOME EOD");
consultantData.Add(("Day_" + day), eventTimeStr);
eventTimeStr = new List<String>();
eventTime = visitStartTime;
++day;
}
else
{
eventTimeStr.Add(eventTime.ToString("h:mm tt") + ": " + req.Reason);
eventTime = req.EndTime;
}
}
consultantData.Add(("Day_" + day), eventTimeStr);
return consultantData;
}
private static String getTimeDiff(OnlineRequest req)
{
DateTime startEventTime = req.StartTime;
DateTime finishEventTime = req.StartTime.AddMinutes(req.Duration);
DateTime visitEndTime = DateTime.MinValue.Date.AddHours(17);
DateTime visitLunchStartTime = DateTime.MinValue.Date.AddHours(12);
if (finishEventTime.CompareTo(visitLunchStartTime) == 0 &&
startEventTime.CompareTo(visitLunchStartTime) > 0)
{
return LUNCH_TIME;
}
else if (startEventTime.CompareTo(visitLunchStartTime) == 0 &&
finishEventTime.CompareTo(visitLunchStartTime) > 0)
{
return LUNCH_TIME;
}
else if (startEventTime.CompareTo(visitLunchStartTime) < 0 &&
finishEventTime.CompareTo(visitLunchStartTime) > 0)
{
return LUNCH_TIME;
}
if (visitEndTime.CompareTo(finishEventTime) < 0)
{
return END_OF_DAY;
}
req.EndTime = finishEventTime;
return "";
}
答案 0 :(得分:1)
我会做这样的事情(非常糟糕的伪代码):
morning = new Block(3*60, 9);
foreach (OnlineRequest req) {
if (req.Duration < morning.getFreeTime()) {
morning.add(req);
}
}
afternoon = new Block(3*60, 13);
foreach (OnlineRequest req not in morning.requests) {
if (req.Duration < afternoon.getFreeTime()) {
afternoon.add(req);
}
}
foreach (OnlineRequest req in morning.requests ) {
print(morning.getStartTime(req))
}
foreach (OnlineRequest req in afternoon.requests ) {
print(afternoon.getStartTime(req))
}
class Block {
List requests;
int blockSize; //minutes
int blockStartTime;
Block(int bS, int bst ) {
blockSize = bs;
blockStartTime = bst;
}
add(OnlineRequest req) {
requests.add(req);
}
getFreeTime() {
sum = 0;
foreach (OnlineRequest req in requests) {
sum += req.Duration;
}
return blockSize - sum;
}
getStartTime(OnlineRequest or) {
sum = 0;
foreach (OnlineRequest req in requests) {
if ( req = or ) {
return sum + blockStartTime;
}
sum += req.Duration;
}
return null;
}
}