Cod sursa(job #629724)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 3 noiembrie 2011 20:53:05
Problema Statistici de ordine Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.89 kb
Program st;
 var a:array [1..3000000] of longint;
   b1,b2:array [1..1 shl 17] of char;
   i,n,t,l,p,aux:longint;
   s:string;
   fi,fo:text;
function citire:longint;
 var aux:longint;
begin
 aux:=0;
 while (s[p]>='0') and (s[p]<='9') and (p<=l) do begin
                                            aux:=aux*10+ord(s[p])-48;
                                             if p=l then begin
                                             read(fi, s);
                                                 p:=0;
                                               l:=length(s);
                                                  end;
                                                 inc(p);
                                                  end;
while ((s[p]<'0') or (s[p]>'9'))and(s<>'') do begin
                                                inc(p);
                                                if p>l then begin
                                                   read(fi, s);
                                                      p:=1;
                                                      l:=length(s);
                                                            end;
                                                  end;
citire:=aux;
end;
procedure sort(l,r:longint);
 var k,i,j,y,x:longint;
 begin
  i:=l; j:=r;
   k:=a[random(r-l)+l];
 while i<j do begin
   while a[i]<k do inc(I);
    while a[j]>k do dec(j);
  if i<=j then
              begin
               y:=a[i]; a[i]:=a[j]; a[j]:=y;
                 inc(i); dec(j);
              end;
   end;
 if t<i then begin if l<j then sort(l,j); end
 else
   if i<r then sort(i,r);
 end;
begin
 assign(fi,'sdo.in');
  assign(fo,'sdo.out');
 settextbuf(fi,b1);
  settextbuf(fo,b2);
 reset(fi); rewrite(fo);
 readln(fi,n,t);
 read(fi,s); l:=length(s); p:=1;
  for i:=1 to n do a[i]:=citire;
 sort(1,n);
 write(fo,a[t]);
 close(fo);
end.