Cod sursa(job #1442306)

Utilizator valentin50517Vozian Valentin valentin50517 Data 24 mai 2015 23:32:24
Problema Cautare binara Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.41 kb
program segmente;
type segment = record
               x,y : integer;
               u : boolean;
              end;
var A : array[1..100] of segment;
    aux : segment;
    i,j,n,rs : integer;

begin
        write('nr de segmente : ');
        readln(n);
        for i:=1 to n do begin
                                write('A[',i,'].x = ');
                                readln(a[i].x);
                                write('A[',i,'].y = ');
                                readln(a[i].y);
                                a[i].u := true;
                         end;
        for i := 1 to n-1 do
        for j := 1 to n-i do
        if a[j].y < a[j+1].y then begin
                                          aux:=a[j];
                                          a[j]:=a[j+1];
                                          a[j+1] := aux;
                                        end;


        for i:=1 to n do begin
                           for j:=i+1 to n do if a[j].y >= a[i].x then begin
                                                                        a[i].u := false;
                                                                        a[j].u := false;
                                                                        end;
        end;
        for i:=1 to n do if a[i].u then inc(rs);
        writeln('Numarul de segmente neintersecate este egal cu ',rs);
        readln;

end.