- using ConsoleApp1;
- using System;//程式庫呼叫
- using System.ComponentModel.DataAnnotations;
- using System.Linq.Expressions;
- using ABC.qq;
- using System.Globalization;
- class Program//負責一部分工作的人
- {
- static string[] meetingDates = { "2018/12/01 14:00", "2018/12/02 15:00", "2018/12/03 10:30", "2018/12/03 15:30", "2018/12/04 15:00" };
- static int[] meetingHours = { 1, 3, 4, 2, 5 };
- static void Main()
- {
-
- try
- {
- //將指定之日期和時間的字串表示,轉換為相等的日期和時間值。
- DateTime newMeeting = Convert.ToDateTime(Console.ReadLine());
- // Console.WriteLine(newMeeting.ToString());
- bool isOverlap = false;
- string meetOverlap = "";
- for(int i=0;i<meetingDates.Length-1;i++)
- {
- DateTime startMeeting = Convert.ToDateTime(meetingDates[i].ToString());
- DateTime endMeeting = startMeeting.AddHours(meetingHours[i]);
- // Console.WriteLine(endMeeting.ToString());
- //比較這個執行個體的值與指定的 DateTime 值,指出這個執行個體早於、同於或晚於指定的 DateTime 值。
- /*
- * 2018/12/02 16:10 2018/12/02 15:00 2018/12/02 18:00
- * 值 描述
- 小於零 這個執行個體早於 value。
- 零 這個執行個體和 value 相同。
- 大於零 這個執行個體晚於 value。
- */
- if (DateTime.Compare(newMeeting,startMeeting)>=0 && DateTime.Compare(newMeeting,endMeeting)<0)
- {
- isOverlap = true;
- meetOverlap = meetingDates[i].ToString();
- break;
- }
-
- }
- if(isOverlap)
- {
- Console.WriteLine("Has already resvered - "+meetOverlap);
- }
- else
- {
- Console.WriteLine("Reservation completed - "+newMeeting.ToString("yyyy/MM/dd HH:mm"));
- }
- }
- catch
- {
- Console.WriteLine("error");
- }
-
- }
-
- }
複製代碼 |