using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;//pt fisiere
namespace intervale
{
class interval
{
private int a, b;//capetele intervalului
//proprietati
public int A
{
get { return a; }
set { a = value; }
}
public int B
{
get { return b; }
set { b = value; }
}
//verificare disjuncte
public bool disjunct(interval b)
{
return this.a > b.B || b.A > this.b;
}
//supraincarcare metoda ToString
public override string ToString()
{
return a + " " + b;
}
}
class Program
{
static void citire(out interval[] A, out int n)
{
StreamReader fin = new StreamReader("intervale.in");
n = int.Parse(fin.ReadLine());//citesc n
A = new interval[n + 1];//creez tabloul de intervale
for(int i=1;i<=n;i++)
{
string l = fin.ReadLine(); //citesc un rand
string[] s = l.Split();//il despart
interval a = new interval();//creez un interval
a.A = int.Parse(s[0]);//capatul stang
a.B = int.Parse(s[1]);//capatul drept
A[i] = a;//pun in vector
}
fin.Close();
}
static void afisare(interval[] A, int n)
{
StreamWriter fout = new StreamWriter("intervale.out");
fout.WriteLine(n);
for (int i = 1; i <= n; i++)
fout.WriteLine(A[i].ToString());
fout.Close();
}
static void Main(string[] args)
{
int n,m=0;
interval[] A,B;
citire(out A, out n);
B=new interval[n+1];
for (int i = 1; i <= n; i++)
{// pt fiecare interval din a
int k = 0;
for (int j = 1; j <= n; j++)//parcurgem
if (A[i].disjunct(A[j]))
k++;//le numar pe cele disjuncte
if (k == n - 1)//daca n-1 sunt disjuncte
B[++m] = A[i];//il punem in B
}
afisare(B, m);
Console.ReadKey();
}
}
}
|