Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- namespace ConsoleApp1
- {
- class Interval
- {
- public int Start;
- public int End;
- public int GetLength()
- {
- return End - Start + 1;
- }
- private bool IsXInInterval(Interval i1, Interval i2)
- {
- return (i1.Start < i2.Start && i2.Start < i1.End) || (i1.Start < i2.End && i2.End < i1.End);
- }
- public bool IsIntersecting(Interval secondInterval)
- {
- return IsXInInterval(this, secondInterval) || IsXInInterval(secondInterval, this) ? true : false;
- }
- }
- class IntervalComparer : IComparer
- {
- public int Compare(object obj1, object obj2)
- {
- var firstInterval = (Interval)obj1;
- var secondInterval = (Interval)obj2;
- return firstInterval.Start.CompareTo(secondInterval.Start);
- }
- }
- class Program
- {
- static void Main()
- {
- int N = 4;
- var intervals = new Interval[N];
- var answer = false;
- for (int i = 0; i < N; i++)
- {
- Interval interval = new Interval();
- var inputLine = Console.ReadLine().Split(' ');
- interval.Start = int.Parse(inputLine[0]);
- interval.End = int.Parse(inputLine[1]);
- intervals[i] = interval;
- }
- Array.Sort(intervals, new IntervalComparer());
- foreach (var firstInterval in intervals)
- foreach (var secondInterval in intervals)
- {
- if (firstInterval != secondInterval)
- {
- if (firstInterval.IsIntersecting(secondInterval))
- answer = true;
- }
- if (answer) break;
- }
- Console.WriteLine(answer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement